我是一个小白,最近应公司要求,用nginx映射服务器的多个端口,但总是不成功,尝试了好久都不行,求帮助呀!
首先,我将默认的location代理成我的服务器端口,使用 http://服务器ip 访问成功!
nginx配置如下:
server {
listen 80;
server_name localhost;
location / {
proxy_pass http://localhost:8118;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
(省略其他默认配置)
}
但是这并不是我想要的效果,我希望用 http://服务器ip/jira 访问8118端口
于是我将改location修改为:
location /jira {
proxy_pass http://localhost:8118;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
访问后网页不能访问,显示:
查看nginx的logs/error.log
2020/04/05 22:33:45 [error] 5180#5304: *1 CreateFile() "D:\nginx-1.16.1/html/static-assets/metal-all.js" failed (3: The system cannot find the path specified), client: (我的电脑ip,这里省略), server: localhost, request: "GET /static-assets/metal-all.js HTTP/1.1", host: "(我的服务器ip,这里省略)", referrer: "(我的服务器ip,这里省略)/jira"
2020/04/05 22:33:45 [error] 5180#5304: *3 CreateFile() "D:\nginx-1.16.1/html/static-assets/metal-all.css" failed (3: The system cannot find the path specified), client: (我的电脑ip,这里省略), server: localhost, request: "GET /static-assets/metal-all.css HTTP/1.1", host: "(我的服务器ip,这里省略)", referrer: "(我的服务器ip,这里省略)/jira"