JeecgBoot
JeecgBoot copied to clipboard
windows环境下nginx配置经验交流
版本号:
3.7.0
问题描述:
按照文档配置nginx积木报表和仪表盘在部署后会出现地址拼接错误或者端口丢失问题,分享下自己的配置,可以在无域名环境下正常使用,配置代码格式调整不好,凑活看了
worker_processes 1;
worker_rlimit_nofile 65535;
events {
worker_connections 10240;
}
http {
include mime.types;
default_type application/octet-stream;
sendfile on;
gzip on;
gzip_min_length 1k;
gzip_comp_level 9;
gzip_types text/plain application/javascript application/x-javascript text/css application/xml text/javascript application/x-httpd-php image/jpeg image/gif image/png;
gzip_vary on;
gzip_disable "MSIE [1-6]\.";
server {
listen 9005;
server_name 【IP地址】;
#前端打的dist资源存放目录
root C:\jeecg-services\jeecgboot-vue3;
location / {
# 用于配合 browserHistory使用
try_files $uri $uri/ /index.html;
}
location ^~ /jeecgboot {
#后台接口地址(我们部署去掉了/jeecg-boot项目名,如果你有请加上)
proxy_pass http://127.0.0.1:8080/jeecg-boot;
proxy_redirect off;
#真实IP获取
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
set $my_proxy_add_x_forwarded_for $proxy_add_x_forwarded_for;
if ($proxy_add_x_forwarded_for ~* "localhost") {
set $my_proxy_add_x_forwarded_for $remote_addr;
}
proxy_set_header X-Forwarded-For $my_proxy_add_x_forwarded_for;
}
# Nginx反向代理后无法使用积木报表的问题
# 1.反向代理不能重设Host,这样将以代理主机的Host信息传给积木后端去请求后续接口逻辑,导致报错
# 2.注掉Host后,不要使用upstream别名,手动设置报表打印完整地址,后续通过反向代理过去即可正常打印
location ^~ /jeecg-boot/jmreport/ {
# proxy_set_header Host $host;
proxy_pass http://127.0.0.1:8080/jeecg-boot/jmreport/;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
}
# Nginx反向代理后无法使用仪表盘预览的问题
# 1.转发后端口丢失,需要手动加上端口
location ^~ /jeecg-boot/drag/ {
proxy_set_header Host $host:$server_port;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
proxy_pass http://127.0.0.1:8080/jeecg-boot/drag/;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
}
}
友情提示:
- 未按格式要求发帖、描述过于简单的,会被直接删掉;
- 描述问题请图文并茂,方便我们理解并快速定位问题;
- 如果使用的不是master,请说明你使用的分支;