2014-04-05 42 views
0

我有一个网站在Apache上运行,我有.htaccess在每个模块文件夹,使他们友好的网址,例如明智的文件夹Nginx配置

/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] “L ocation“指令不允许在这里/var/www/mysite.com/public_html/modules/MODULE1/nginx.conf:1

回答

0

这是你的完整的nginx.conf吗?

它看起来像你的server块不在http块内,其中it should be

+0

不,它不是完整的代码,我只在这个文件中添加了额外的代码“/var/www/mysite.com/public_html/modules/MODULE1/nginx.conf;”实现seo朋友的网址。 –

+0

根据你的错误,问题出现在第1行的'/ var/www/mysite.com/public_html/modules/MODULE1/nginx.conf'文件中。如果你共享了该文件的全部内容并且/ etc/nginx/nginx.conf文件中包含该文件的行。如果需要,您可以用样本数据值替换SEO /隐私数据。 –

+0

http { server_names_hash_bucket_size 64; include /etc/nginx/mime.types; default_type application/octet-stream; log_format主 '$ REMOTE_ADDR - $ REMOTE_USER [$ time_local] “$请求”' '$ $状态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; 包括/etc/nginx/conf.d/*.conf; 包括/var/www/mysite.com/public_html/modules/*/nginx.conf; } –