nginx反向代理配置演示,包括静态资源处理,百分百成功
nginx代理配置演示,包括静态资源处理,百分百成功。 最近在测试nginx代理时,遇到了一个问题就是,可以成功接受后端处理的数据, 但是静态资源却出现了404 错误。经过搜索相关文档终于解决了nginx代理静态资源的问题。 详细代码如下。自行修改相关参数。。。
1
2
3
4
5
6
7
8
9
10
location / {
proxy_pass http://127.0.0.1:9090;
proxy_set_header Host $host;
proxy_redirect off;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_connect_timeout 300;
proxy_read_timeout 300;
proxy_send_timeout 300;
}
关键是下面的代码,就是nginx处理静态资源的关键。
1
2
3
4
location ^~ /static/ {
root /var/www/web/;
}
如果镜像资源和图片上传目录是分开的。就是说不在同一目录下,则要分开处理,比如
1
2
3
4
location ^~ /upload/ {
root /var/www/web/;
}
nginx -t
service nginx restart
💘 相关文章
- 解决nginx反向代理验证码不显示的方法
- Nginx使用Memcached缓存加速wordpress,秒开网站
- nginx安全设置之-限制IP来源只能为cloudflare
- 重新编译nginx,以便支持最新的quic(http3)以及 brotli 压缩
- FreeBSD 安装PHP7.4 和 Nginx
- directadmin的安装折腾及更改directadmin为nginx记录
- Nginx – Unit nginx.service is masked的解决方法
- hiawatha服务器反向代理配置的一些坑
- nginx: [warn] "ssl_stapling" ignored, issuer certificate not found for certificate的错误解决方法
- Configure nginx to only allow cloudflare's IP to connect to the server shell script