post方式访问nginx静态页面报405/404解决方法

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个端口。

 

 

转载于:https://www.cnblogs.com/linux-ng/p/9889289.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值