nginx不转发到静态服务器

时间:2013-01-09 07:24:05

标签: nginx

我有两台服务器在后台运行,我希望nginx能够将代理转发给它们。

我希望nginx在端口80上运行。当用户导航到http://localhost:80/时,他应该转发到http://localhost:3501。但是我仍然在http://localhost:80看到默认的nginx页面。我在我的localhost上安装了nginx,并且正在同一个盒子中进行测试。

server {
               listen 80;
               server_name _;

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

1 个答案:

答案 0 :(得分: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. 在“server - > location”中添加proxy_pass:
    location / {
    root html;
    index index.html index.htm;
    proxy_pass http://backend-testserver;
    }

相关问题