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