2016-04-28 77 views
2

我使用閃亮的服務器來建立一個端口3838上的Web應用程序,當我在我的服務器上使用nginx它運作良好。但是,當我停止我的服務器上的nginx,並嘗試使用泊塢窗nginx的,我發現該網站涉及到一個「502-壞門之路」的錯誤和nginx的日誌顯示:docker nginx連接拒絕連接到上游

2016/04/28 18:51:15 [error] 8#8: *1 connect() failed (111: Connection refused) while connecting to upstream, ... 

我通過這個命令安裝搬運工,nginx的:

sudo docker pull nginx 

我泊塢窗命令行是一樣的東西(爲清楚,我添加一些縮進):

sudo docker run --name docker-nginx -p 80:80 
    -v ~/docker-nginx/default.conf:/etc/nginx/conf.d/default.conf 
    -v /usr/share/nginx/html:/usr/share/nginx/html nginx 

我在我的家目錄創建一個文件夾名「泊塢窗,nginx的」,動我的nginx的conf在此文件夾中的文件,然後刪除以防萬一我的原始配置文件在etc/nginx目錄中。

我的nginx的conf文件看起來像這樣:

server { 
    listen 80 default_server; 
    # listen [::]:80 default_server ipv6only=on; 

    root /usr/share/nginx/html; 
    index index.html index.htm; 

    # Make site accessible from http://localhost/ 
    server_name localhost; 

    location/{ 
      proxy_pass http://127.0.0.1:3838/; 
      proxy_redirect http://127.0.0.1:3838/ $scheme://$host/; 
      auth_basic "Username and Password are required"; 
      auth_basic_user_file /etc/nginx/.htpasswd; 
      # enhance the performance 
      proxy_http_version 1.1; 
      proxy_set_header Upgrade $http_upgrade; 
      proxy_set_header Connection "upgrade"; 
      proxy_set_header Host $host; 
    } 
} 

回答

3

你必須定義upstrem指令。目前,您的nginx無法代理您的Web應用程序。

http://nginx.org/en/docs/http/ngx_http_upstream_module.html

upstream backend { 
    server backend1.example.com  weight=5; 
    server backend2.example.com:8080; 
    server unix:/tmp/backend3; 

    server backup1.example.com:8080 backup; 
    server backup2.example.com:8080 backup; 
} 

server { 
    location/{ 
     proxy_pass http://backend; 
    } 
} 
相關問題