如下所示:访问127.0.0.1的80端口时,会将默认请求转发为127.0.0.1:8080上面。
成功启动nginx后,静态资源(js,css,img等)无法访问
listen 80;
server_name 127.0.0.1;
#charset koi8-r;
#access_log logs/host.access.log main;
location / {
root html;
index index.html index.htm;
proxy_pass http://127.0.0.1:8080/;
}
此时,需要增加配置,如下图所示
location ~ .* {
proxy_pass http://127.0.0.1:8080;
proxy_set_header Host $http_host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
指定静态资源代理路径即可成功访问!