首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >nginx未转发到静态服务器

nginx未转发到静态服务器
EN

Stack Overflow用户
提问于 2013-01-09 15:24:05
回答 1查看 65关注 0票数 0

我有两台服务器在后台运行,我想让nginx反向代理这两台服务器。

我希望nginx在端口80上运行。当用户导航到http://localhost:80/时,他应该被转发到http://localhost:3501。然而,我仍然在http://localhost:80上看到了默认的nginx页面。我在我的本地主机上安装了nginx,并在同一个机器上进行测试。

代码语言:javascript
复制
server {
               listen 80;
               server_name _;

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

回答 1

Stack Overflow用户

发布于 2013-01-09 15:45:28

  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

}

  • 在“proxy_pass -> location”中添加服务器:

location / {

root html;

index index.html index.htm;

proxy_pass http://backend-testserver;

}

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/14230197

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档