在docker中用nginx,要是你的工程部署在外面,就要注意,127.0.0.1是容器里的ip,你要用你的宿主机的ip。不然会报错:

  1. connect() failed (111: Connection refused) while connecting to upstream, client: 172.19.0.1, server: goodcorn.com, request: "GET /api/v1/login/captchaid HTTP/1.1", upstream: "http://127.0.0.1:10088/api/v1/login/captchaid", host: "goodcorn.com", referrer: "http://goodcorn.com/user/login"

正确的配置如下:

  1. upstream goodcorn_api {
  2. server 10.1.118.76:10088 max_fails=5 fail_timeout=10; #这个ip一定不要用127.0.0.1,毕竟我的go代码不跑在容器里
  3. keepalive 20000;
  4. }
  5. server {
  6. listen 80;
  7. #listen [::]:80 default_server ipv6only=on;
  8. # For https
  9. # listen 443 ssl default_server;
  10. # listen [::]:443 ssl default_server ipv6only=on;
  11. # ssl_certificate /etc/nginx/ssl/default.crt;
  12. # ssl_certificate_key /etc/nginx/ssl/default.key;
  13. server_name goodcorn.com;
  14. root /var/www/src/github.com/LyricTian/gin-admin/web/dist;
  15. index index.php index.html index.htm;
  16. location /api {
  17. proxy_pass http://goodcorn_api/api;
  18. }
  19. location / {
  20. try_files $uri $uri/ /index.html;
  21. }
  22. location ~ /\.ht {
  23. deny all;
  24. }
  25. }
  26. server {
  27. listen 80;
  28. server_name api.goodcorn.com;
  29. location / {
  30. proxy_pass http://goodcorn_api;
  31. }
  32. location ~ /\.ht {
  33. deny all;
  34. }
  35. }

附上一些docker的操作吧:

  1. docker-compose logs -f nginx

还是docker-compose好用。哈哈。

分类: web

标签:   docker