各位大大,问下关于rewrite的问题
By
hwqshwq
at 2017-07-18 • 1人收藏 • 6053人看过
我在nginx中,将nginx.conf配置到host ,安装后,可以进入首页,但点击注册的是时候,爆error request 错误,如果将host的nginx.conf的内容去掉,就报404错误。是什么原因呢
18 个回复 | 最后更新于 2020-11-15
回复#1 @lincanbin :
目前使用的是5.0.1了 ,用
rewrite ^(.*)/favorites(/page/([0-9]+))?$ $1/favorites.php?page=$2 last; rewrite ^(.*)/forgot$ $1/test.php last; rewrite ^(.*)/goto/([0-9]+)-([0-9]+)$ $1/goto.php?topic_id=$1&post_id=$2 last; rewrite ^(.*)/json/([0-9a-z_-]+)$ $1/json.php?action=$1 last; rewrite ^(.*)/login$ $1/login.php last; rewrite ^(.*)/manage$ $1/manage.php last; rewrite ^(.*)/new$ $1/new.php last; rewrite ^(.*)/notifications$ $1/notifications.php last; rewrite ^(.*)/oauth-([0-9]+)$ $1/oauth.php?app_id=$1 last; rewrite ^(.*)/page/([0-9]+)$ $1/index.php?page=$1 last; rewrite ^(.*)/register$ $1/register.php last; rewrite ^(.*)/reply$ $1/reply.php last;
这种,目测好了 等搞好了我在试下新的 3q大大
回复#4 @hwqshwq :
5.9.0版本的,试试这个Nginx规则:
# nginx configuration location ~ ^/.git { return 403; } location ~ ^/controller { return 403; } location ~ ^/docker_resources { return 403; } location ~ ^/library { return 403; } location ~ ^/service { return 403; } location ~ ^/view { return 403; } location / { if ($request_method ~ "^TRACE"){ return 403; } if (!-e $request_filename){ rewrite ^/(.*)/$ /$1 redirect; } if (!-e $request_filename){ rewrite ^(.*)$ /index.php break; } }
回复#12 @hwqshwq :
location ^~ /php_bbs { root /var/www/example.com;#你的程序路径 index index.php index.html index.htm; try_files $uri $uri/ /php_bbs/index.php; #下面是你的PHP的CGI配置,根据自己情况写写 location ~ \.php { fastcgi_split_path_info ^(.*\.php)(.*)$; include fastcgi_params; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; fastcgi_param PATH_INFO $fastcgi_path_info; fastcgi_param PATH_TRANSLATED $document_root$fastcgi_path_info; fastcgi_pass 127.0.0.1:9000; } }
登录后方可回帖
目测粘贴错了地方?
有截图跟完整的Nginx配置文件吗?