我一直在努力地争取在NGINX反向代理后面工作,但我只是做得不好。我的服务在docker容器中运行,我想使用以下示例网址访问它们:
我的服务:
http://service-host.example.com/my-service1
昂首阔步:
http://service-host.example.com/my-service1/api
我的嵌套位置块如下所示:
location /my-service1 {
resolver 127.0.0.11 valid=30s;
set $upstream my-host.example.com;
proxy_pass http://$upstream/home;
location ~ /api {
resolver 127.0.0.11 valid=30s;
set $upstream my-host.example.com;
proxy_pass http://$upstream/swagger-ui.html;
}
location ~ /webjars {
resolver 127.0.0.11 valid=30s;
set $upstream my-host.example.com;
proxy_pass http://$upstream/;
}
location ~ /v2 {
resolver 127.0.0.11 valid=30s;
set $upstream my-host.example.com;
proxy_pass http://$upstream/;
}
location ~ /swagger-resources {
resolver 127.0.0.11 valid=30s;
set $upstream my-host.example.com;
proxy_pass http://$upstream/;
}
}
我的NGINX日志看起来像这样:
GET /my-service1/api/ HTTP/2.0" 200
GET /my-service1/api/webjars/springfox-swagger-ui/springfox.css?v=2.9.2 HTTP/2.0" 200
GET /my-service1/api/webjars/springfox-swagger-ui/swagger-ui-bundle.js?v=2.9.2 HTTP/2.0" 200
GET /my-service1/api/webjars/springfox-swagger-ui/swagger-ui.css?v=2.9.2 HTTP/2.0" 200
GET /my-service1/api/webjars/springfox-swagger-ui/springfox.js?v=2.9.2 HTTP/2.0" 200
GET /my-service1/api/webjars/springfox-swagger-ui/swagger-ui-standalone-preset.js?v=2.9.2 HTTP/2.0" 200
无需通过NGINX进行直接测试,该过程就可以通过/ v2 / api和/ swagger-resources的GET进一步进行。使用反向代理在此之前就卡住了。
关于如何解决此问题的任何建议?
编辑:这是不尝试反向代理时的NGINX日志,但直接转到http://myservice.example.com/swagger-ui.html即可正常工作!
myservice.example.com 192.168.1.30 - - [12/Feb/2019:09:59:44 +0000] "GET /swagger-ui.html HTTP/2.0" 200 3318 "-" "Mozilla/5.0 (Windows NT 6.1; rv:60.0) Gecko/20100101 Firefox/60.0"
myservice.example.com 192.168.1.30 - - [12/Feb/2019:09:59:44 +0000] "GET /webjars/springfox-swagger-ui/springfox.css?v=2.9.2 HTTP/2.0" 200 2894 "https://myservice.example.com/swagger-ui.html" "Mozilla/5.0 (Windows NT 6.1; rv:60.0) Gecko/20100101 Firefox/60.0"
myservice.example.com 192.168.1.30 - - [12/Feb/2019:09:59:44 +0000] "GET /webjars/springfox-swagger-ui/swagger-ui.css?v=2.9.2 HTTP/2.0" 200 154488 "https://myservice.example.com/swagger-ui.html" "Mozilla/5.0 (Windows NT 6.1; rv:60.0) Gecko/20100101 Firefox/60.0"
myservice.example.com 192.168.1.30 - - [12/Feb/2019:09:59:45 +0000] "GET /webjars/springfox-swagger-ui/swagger-ui-bundle.js?v=2.9.2 HTTP/2.0" 200 1448844 "https://myservice.example.com/swagger-ui.html" "Mozilla/5.0 (Windows NT 6.1; rv:60.0) Gecko/20100101 Firefox/60.0"
myservice.example.com 192.168.1.30 - - [12/Feb/2019:09:59:45 +0000] "GET /webjars/springfox-swagger-ui/springfox.js?v=2.9.2 HTTP/2.0" 200 96207 "https://myservice.example.com/swagger-ui.html" "Mozilla/5.0 (Windows NT 6.1; rv:60.0) Gecko/20100101 Firefox/60.0"
myservice.example.com 192.168.1.30 - - [12/Feb/2019:09:59:45 +0000] "GET /webjars/springfox-swagger-ui/swagger-ui-standalone-preset.js?v=2.9.2 HTTP/2.0" 200 440850 "https://myservice.example.com/swagger-ui.html" "Mozilla/5.0 (Windows NT 6.1; rv:60.0) Gecko/20100101 Firefox/60.0"
myservice.example.com 192.168.1.30 - - [12/Feb/2019:09:59:46 +0000] "GET /swagger-resources/configuration/ui HTTP/2.0" 200 450 "https://myservice.example.com/swagger-ui.html" "Mozilla/5.0 (Windows NT 6.1; rv:60.0) Gecko/20100101 Firefox/60.0"
myservice.example.com 192.168.1.30 - - [12/Feb/2019:09:59:46 +0000] "GET /swagger-resources/configuration/security HTTP/2.0" 200 2 "https://myservice.example.com/swagger-ui.html" "Mozilla/5.0 (Windows NT 6.1; rv:60.0) Gecko/20100101 Firefox/60.0"
myservice.example.com 192.168.1.30 - - [12/Feb/2019:09:59:46 +0000] "GET /swagger-resources HTTP/2.0" 200 90 "https://myservice.example.com/swagger-ui.html" "Mozilla/5.0 (Windows NT 6.1; rv:60.0) Gecko/20100101 Firefox/60.0"
myservice.example.com 192.168.1.30 - - [12/Feb/2019:09:59:46 +0000] "GET /v2/api-docs HTTP/2.0" 200 8387 "https://myservice.example.com/swagger-ui.html" "Mozilla/5.0 (Windows NT 6.1; rv:60.0) Gecko/20100101 Firefox/60.0"
答案 0 :(得分:0)
使用此conf在服务器(NET CORE)中工作的麻烦者
location / {
#root /srv/ftp;
#index index.html index.htm;
proxy_pass http://localhost:5000;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection keep-alive;
proxy_set_header Host $host;
proxy_cache_bypass $http_upgrade;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
}