这是nginx error.log原话html
我这个服务相对简单 Docker容器 spring cloud服务分别是:service服务提供、网关api、运营api、 端口分别是8090服务、8091网关api、8092运营 api
效果以下:
这没什么好说的
而后开始搭建nginxnginx
docker run --name nginx -d -p 80:80 -p 443:443 -v /docker/nginx/logs:/var/log/nginx -v /docker/nginx/conf/nginx.conf:/etc/nginx/nginx.conf -v /docker/nginx/www:/usr/share/nginx/html nginx
开启ssl
最后把安全证书 cp到容器 :docker cp /root/cert/ 0f186a79f090:/root/
最后启动访问:docker start 0f186a79f090
访问后:
web
2020/03/18 04:45:15 [error] 5#5: *1 connect() failed (111: Connection refused) while connecting to upstream, client: xxx.xxx.xxx.xxx, server: xxx.xxx.xxx.xxx, request: "GET /v1/api/xxx HTTP/1.1", upstream: "http://127.0.0.1:8091/v1/api/xxx", host: "xxx.xxx.xxx.xxx" 2020/03/18 04:45:15 [error] 5#5: *1 connect() failed (111: Connection refused) while connecting to upstream, client: xxx.xxx.xxx.xxx, server: xxx.xxx.xxx.xxx, request: "GET /favicon.ico HTTP/1.1", upstream: "http://127.0.0.1:8091/xxx", host: "xxx.xxx.xxx.xxx", referrer: "https://xxx.xxx.xxx.xxx/v1/api/xxxx"
解决方案:
个人conf server是这样配置的spring
server { # IPv4 listen 80; listen 443 ssl; # IPv6 listen [::]:80; listen [::]:443 ssl; server_name xxx.xxx.xxx.xxx; # certs sent to the client in SERVER HELLO are concatenated in ssl_certificate ssl_certificate /root/cert/xxx.xxx.xxx.xxx.pem; ssl_certificate_key /root/cert/xxx.xxx.xxx.xxx.key; # curl https://ssl-config.mozilla.org/ffdhe2048.txt > /etc/nginx/ssl/dhparam.pem # ssl_dhparam ssl/dhparam.pem; location / { client_max_body_size 20M; proxy_pass http://xxx.xxx.xxx.xxx:8091; proxy_set_header Host $host; proxy_set_header X-Real-IP $remote_addr; } access_log /var/log/nginx/xxx.xxx.xxx.xxx.log main; error_log /var/log/nginx/xxx.xxx.xxx.xxx.log; }
location / { client_max_body_size 20M; # 个人问题就是这里 原来是:proxy_pass http://localhost:8091; # 后来改为:proxy_pass http://127.0.0.1:8091; 也不行! # 改为解决:proxy_pass http://xxx.xxx.xxx:8091; ok了!(xxx.xxx.xxx是你服务器公网IP 如:139.172.99.21:8091) proxy_pass http://xxx.xxx.xxx.xxx:8091; proxy_set_header Host $host; proxy_set_header X-Real-IP $remote_addr; }