我一生中第一次使用 nginx。
我开始知道 nginx 不遵循 htaccess。
我们在 htaccess 中应用的重写规则应该在 nginx conf 文件中应用。我不知道怎么做。
我打开了nginx conf文件。我使用这个转换器将我的 htaccess 转换为 nginx 配置文件。我附上了 htaccess 和等效的配置文件。
我什至不知道是否启用了重写模式?或者我会说我不知道找到它的确切方法。
htaccess 代码
RewriteEngine on
# if a directory or a file exists, use it directly
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
# otherwise forward it to index.php
RewriteRule . index.php
php_value session.cookie_domain .abc.in
Nginx 配置文件
user www-data;
worker_processes 4;
pid /var/run/nginx.pid;
events {
worker_connections 768;
# multi_accept on;
}
http {
##
# Basic Settings
##
sendfile on;
tcp_nopush on;
tcp_nodelay on;
keepalive_timeout 65;
types_hash_max_size 2048;
# server_tokens off;
# server_names_hash_bucket_size 64;
# server_name_in_redirect off;
include /etc/nginx/mime.types;
default_type application/octet-stream;
##
# Logging Settings
##
access_log /var/log/nginx/access.log;
error_log /var/log/nginx/error.log;
##
# Gzip Settings
##
#rewrite on;
gzip on;
gzip_disable "msie6";
# gzip_vary on;
# gzip_proxied any;
# gzip_comp_level 6;
# gzip_buffers 16 8k;
# gzip_http_version 1.1;
# gzip_types text/plain text/css application/json application/x-javascript text/xml application/xml application/xml+rss text/javascript;
##
# nginx-naxsi config
##
# Uncomment it if you installed nginx-naxsi
##
#include /etc/nginx/naxsi_core.rules;
##
# nginx-passenger config
##
# Uncomment it if you installed nginx-passenger
##
#passenger_root /usr;
#passenger_ruby /usr/bin/ruby;
##
# Virtual Host Configs
##
include /etc/nginx/conf.d/*.conf;
include /etc/nginx/sites-enabled/*;
server
{
listen 80;
server_name abc.in;
# nginx configuration
location /
{
if (!-e $request_filename)
{
rewrite ^(.*)$ /index.php;
}
}
}
}