我正在将我的mediawiki网站转换为使用nginx作为静态文件的前端,后端用于php的apache.到目前为止,我已经完成了所有工作,除了当我查看根目录"example.com"时它尝试提供目录列表并给出403错误,因为我已经禁用并且没有索引文件.
我现在使用的apache重写规则很简单:
RewriteRule ^$ /wiki/Main_Page [L]
Run Code Online (Sandbox Code Playgroud)
我在nginx中尝试过与location指令类似的东西,但它不起作用:
location = / {
rewrite "^$" /wiki/Main_Page;
}
Run Code Online (Sandbox Code Playgroud)
我的其他位置指令是:
location / {
try_files $uri $uri/ @rewrite;
}
location @rewrite {
rewrite ^/wiki/(.*)$ /w/index.php?title=$1&$args;
}
location ~* \.(js|css|png|jpg|jpeg|gif|ico)$ {
try_files $uri /w/index.php?title=$1&$args;
expires max;
log_not_found off;
}
location ~ \.php?$ {
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $remote_addr;
proxy_set_header Host $host;
proxy_pass http://127.0.0.1:8080;
}
Run Code Online (Sandbox Code Playgroud)
我可以简单地在其中放入一个带有标题('Location:')的index.php文件,但我宁愿用重写规则正确地执行它.
我在网上找到的使用nginx运行mediawiki的所有示例都将wiki作为wiki.example.com而不是/ wiki /子目录运行.
编辑:我也尝试像这样添加到try_files:try_files $uri $uri/ @rewrite /wiki/Main_Page;具有相同的403错误结果.
Kad*_*aan 36
我在nginx irc聊天中找到了帮助.
基本上我需要做的是使用return而不是重写.所以我改变了这个:
location = / {
rewrite "^$" /wiki/Main_Page;
}
Run Code Online (Sandbox Code Playgroud)
对此:
location = / {
return 301 http://www.example.com/wiki/Main_Page;
}
Run Code Online (Sandbox Code Playgroud)
小智 20
我更喜欢使用:
location = / {
return 301 http://$host/wiki/Main_Page;
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
61409 次 |
| 最近记录: |