2013-01-09 81 views
0

我有兩臺服務器在後臺運行,我希望nginx將它們的代理轉換爲它們。nginx isnt轉發到靜態服務器

我想讓nginx運行在端口80上。當用戶導航到http://localhost:80/時,他應該被轉發到http://localhost:3501。不過,我仍然可以在http://localhost:80看到默認的nginx頁面。我在我的本地主機上安裝了nginx,並從同一個盒子進行測試。

server { 
       listen 80; 
       server_name _; 

       location ^~/api/* { 
         proxy_pass http://localhost:8000; 
       } 
       location ^~/* { 
         proxy_pass http://localhost:3501; 
       } 
     } 

回答

1
  1. 添加上游:
    upstream backend-testserver {
    server 127.0.0.1:3501 weight=1 max_fails=2 fail_timeout=30s; # server 1
    server 127.0.0.1:3502 weight=1 max_fails=2 fail_timeout=30s; # server 2
    }

  2. 添加proxy_pass在 「服務器 - >位置」:
    location/{
    root html;
    index index.html index.htm;
    proxy_pass http://backend-testserver;
    }

相關問題