rewrite 帮看一下 注册404
By nohup
at 2018-05-09
1人收藏 • 5508人看过
location / { include rewrite.conf root "C:/Users/Administrator/Desktop/wnmps/webroot"; index index.php index.html index.htm; }
- 登录后方可回帖
我和你同样的问题,我发现安装包的nginx.conf里就一句是
location / { try_files $uri $uri/ /index.php?$query_string; }# rewrite
我记得以前的老版本有一堆规则
rewrite ^([^\.]*)/dashboard$ $1/dashboard.php; rewrite ^([^\.]*)/favorites(/page/([0-9]*))?$ $1/favorites.php?page=$3 last; rewrite ^([^\.]*)/json/([0-9a-z_-]+)$ $1/json.php?action=$2 last; rewrite ^([^\.]*)/login$ $1/login.php; rewrite ^([^\.]*)/manage$ $1/manage.php; rewrite ^([^\.]*)/new$ $1/new.php; rewrite ^([^\.]*)/notifications$ $1/notifications.php; rewrite ^([^\.]*)/page/([0-9]+)$ $1/index.php?page=$2 last; rewrite ^([^\.]*)/register$ $1/register.php; rewrite ^([^\.]*)/reply$ $1/reply.php; rewrite ^([^\.]*)/robots.txt$ $1/robots.php; rewrite ^([^\.]*)/search.xml$ $1/open_search.php; rewrite ^([^\.]*)/search/(.*?)(/page/([0-9]*))?$ $1/search.php?keyword=$2&page=$4 last; rewrite ^([^\.]*)/settings$ $1/settings.php; rewrite ^([^\.]*)/sitemap-(topics|pages|tags|users|index)(-([0-9]+))?.xml$ $1/sitemap.php?action=$2&page=$4 last; rewrite ^([^\.]*)/statistics$ $1/statistics.php; rewrite ^([^\.]*)/t/([0-9]+)(-([0-9]*))?$ $1/topic.php?id=$2&page=$4 last; rewrite ^([^\.]*)/tag/(.*?)(/page/([0-9]*))?$ $1/tag.php?name=$2&page=$4 last; rewrite ^([^\.]*)/tags/following(/page/([0-9]*))?$ $1/favorite_tags.php?page=$3 last; rewrite ^([^\.]*)/u/(.*?)$ $1/user.php?username=$2 last; rewrite ^([^\.]*)/users/following(/page/([0-9]*))?$ $1/favorite_users.php?page=$3 last; rewrite ^([^\.]*)/upload_controller$ $1/upload_controller.php; #QSA is automatic in nginx. rewrite ^([^\.]*)/view-(desktop|mobile)$ $1/view.php?view=$2 last;
现在装5.9.0用哪种都是404了。。。
回复#3 @lincanbin :
额,奇怪了,那为什么我还是404,我还去github上参考了那这个文件
https://github.com/lincanbin/Carbon-Forum/blob/master/docker_resources/nginx_default.conf
除了这一句
fastcgi_split_path_info ^(.+\.php)(/.+)$;
以外并没有什么差别,我的php cfi.fix_pathinfo=0的
以下是我的nginx站点配置
server { listen 80; server_name localhost; #charset koi8-r; access_log D:/nginx/html/bbs/access.log; error_log D:/nginx/html/bbs/error.log; root D:/nginx/html/bbs; index index.php; location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)$ { expires 7d; access_log off; } location ~ .*\.(js|css)$ { expires 12h; access_log off; } # rewrite location / { try_files $uri $uri/ /index.php?$query_string; } location /.git { deny all; return 403; } location /controller { deny all; return 403; } location /docker_resources { deny all; return 403; } location /library { deny all; return 403; } location /service { deny all; return 403; } location /view { deny all; return 403; } error_page 404 /404.php; error_page 500 502 503 504 /500.html; location = /500.html { root /usr/local/nginx/html; } location ~ \.php$ { fastcgi_split_path_info ^(.+\.php)(/.+)$; fastcgi_pass 127.0.0.1:9000; #fastcgi_pass unix:/var/run/phpfpm.sock; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; include fastcgi_params; } # deny access to .htaccess files, if Apache's document root # concurs with nginx's one # location ~ /\.ht { deny all; } }
回复#4 @test2 :
root /www/web/carbon/public_html; include /www/web/carbon/public_html/nginx.conf;
我说过了,root在外面。
https://www.94cb.com/t/5672#Post26809
这是我目前完整的配置文件。
回复#5 @lincanbin :
似乎明白了。。。
回复#6 @test2 :
你的root在location里面不是吗?
回复#7 @lincanbin :
我的root在server下,在location里的那个是楼主的配置。
我在想是不是这一句的问题
try_files $uri $uri/ /index.php?$query_string;
因为我的站点搭在根目录下的bbs文件夹里,这一句是否需要修改?
回复#8 @test2 :
server { listen 80; listen [::]:80; server_name www.94cb.com 94cb.com m.94cb.com api.94cb.com cdn.94cb.com; # 设置Carbon Forum路径 root /www/web/carbon/public_html; index index.html index.php index.htm; # 在这里引入Rewrite include /www/web/carbon/public_html/nginx.conf; # 转发PHP请求的php的cgi location ~ \.php(.*)$ { fastcgi_pass unix:/tmp/php-71-cgi.sock; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME $DOCUMENT_ROOT$fastcgi_script_name; fastcgi_param PATH_INFO $2; include fcgi.conf; } }
这是目前官网在跑的Nginx上的配置,你参考下。
回复#8 @test2 :
你在二级目录的话,那显然——确实需要把路径修改为对应的二级路径。
回复#10 @lincanbin :
我的root是
root D:/nginx/html;
我把try_file这里的第一个$uri对应的/index.php改成/bbs/index.php
似乎不行,请教
回复#11 @test2 :
location开头的路径也要对应修改的。
所以如果是二级目录的话,这么改就对了
... server { listen 80; server_name localhost; root /xxx/www; index index.php index.html index.htm; location /carbon/ { try_files $uri $uri/ /carbon/index.php?$query_string; } } ...
回复#13 @callblueday :
多谢,的确是没有改location后的内容。
回复#12 @lincanbin :
多谢。另请问验证码不显示,是不是需要某个php组件加载?
回复#16 @lincanbin :
没有,我用的sublime text,我看了下我又gd2.dll加载了,但是默认拉回来的ext文件里没有gd.dll
回复#17 @test2 :
所以是有加载吗?