问题描述:
本地运行项目打开swaager可以用,但是上传到服务器用nginx做反向代理的时候返回"error": "no response from server",且网址有端口,swaager的请求url端口丢失,使用了默认80端口
问题原因:
因为在配置nginx反向代理的时候,没注意到配置代理的端口,导致端口丢失!
解决方案:
使用nginx端口映射的时候,proxy_set_header 配置不一样
server_name是域名的情况下:listen是80,且proxy_set_header Host $host;
server { server_name xxxx.xxxx.com; listen 80; location / { proxy_set_header Host $host; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_http_version 1.1; proxy_read_timeout 21600s; proxy_set_header Upgrade $http_upgrade; proxy_set_header Connection "upgrade"; proxy_pass http://127.0.0.1:8080; } }
server_name是服务器ip的情况下:listen是映射的端口,且proxy_set_header Host $host:$server_port;
server { server_name 192.168.xxx.xxx; listen 8888; location / { 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_http_version 1.1; proxy_read_timeout 21600s; proxy_set_header Upgrade $http_upgrade; proxy_set_header Connection "upgrade"; proxy_pass http://127.0.0.1:8080; } }