首页 > 技术文章 > post方式访问nginx静态页面报405/404解决方法

linux-ng 2018-11-01 14:59 原文

nginx.conf配置:

增加图片中红色框中内容

###需要转换的ip地址及端口,这边之所以使用81端口,是因为需要访问的页面,不是nginx默认启动目录中的页面,所以增加一个server,这个server使用81端口。

upstream static_backend {
server 111.111.111.111:81;

###添加的服务启动路径为/

location / {
root /;
#root html;
index index.html index.htm;
}

###/media/attachments定义为/attachments目录。

location /attachments {
root /;
rewrite ^/attachments/(.*)$ /media/attachments/$1 break;
}

###将post方式转为get方式;405重定向为200;根据server需要,将下面这段添加到server中。

error_page 405 =200 @405;
location @405 {
root /;
proxy_method GET;
proxy_pass http://static_backend;
}

###访问地址是:ip:端口/location中配置的地址/页面名称

###之所以报404 是因为找不到页面路径,可以看nginx.log中日志,每次操作日志中都会带上访问路径。

 

###配置修改后,保存,重启nginx,可以看到nginx使用的2个端口。

 

 

推荐阅读