我有一个运行在apache上的网站,我在每个模块文件夹中都有.htaccess,以使它们成为友好的URL,例如。
/var/www/mysite.com/public_html/modules/MODULE1/.htaccess /var/www/mysite.com/public_html/modules/MODULE2/.htaccess /var/www/mysite.com/public_html/modules/MODULE3/.htaccess
我在每个.htaccess文件中都有以下代码
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^(.*/[^\./]*[^/])$ /$1/
RewriteRule ^([a-zA-Z0-9\/_-]*)$ ./index.php [QSA,L]
</IfModule>
现在,我将服务器更改为Nginx,并在“/etc/nginx/nginx.conf”中包含以下代码
包括/var/www/mysite.com/public_html/modules / * / nginx.conf;
现在我的问题是,在nginx.conf文件中放入什么来实现与.htaccess一样的目标?
我在“/etc/nginx/nginx.conf”中有以下代码
http {
server_names_hash_bucket_size 64;
include /etc/nginx/mime.types;
default_type application/octet-stream;
log_format main '$remote_addr - $remote_user [$time_local] "$request" ' '$status $body_bytes_sent "$http_referer" ' '"$http_user_agent" "$http_x_forwarded_for"';
access_log /var/log/nginx/access.log main;
sendfile on;
keepalive_timeout 65;
include /etc/nginx/conf.d/*.conf;
include /var/www/mysite.com/public_html/modules/*/nginx.conf;
}
我在“/var/www/mysite.com/public_html/modules/MODULE1/nginx.conf”中有以下代码
location / {
if (-d $request_filename){
set $rule_0 1$rule_0;
}
if ($rule_0 = "1"){
rewrite ^/(.*/[^./]*[^/])$ /$1/;
}
rewrite ^/([a-zA-Z0-9/_-]*)$ /./index.php last;
}
我在“/var/www/mysite.com/public_html/modules/*/nginx.conf”中尝试了不同的代码并遇到了这些错误
nginx:[emerg]“location”指令不允许在/var/www/mysite.com/public_html/modules/MODULE1/nginx.conf:1