gpt4 book ai didi

node.js - Nginx 配置错误反向代理在启动 nginx 时显示 "Welcome to nginx"

转载 作者:行者123 更新时间:2023-12-04 19:01:13 27 4
gpt4 key购买 nike

这是我第一次玩 nginx。我有 2 台快速服务器在我的 localhost 中运行,端口为 3001 和 3002。运行良好。
我正在使用 ubuntu,这些是我为 nginx 采取的步骤。

  • 首先我使用 sudo apt-get install nginx
  • 删除站点启用和站点可用中的默认文件须藤
    -f 默认
  • 在我有这些代码的可用站点中创建默认文件(现在只是尝试在端口 3001 中运行一台服务器。)须藤 vi 默认
    服务器
    {
    听 80;
    地点 /
    {
    代理通行证“http://192.168.100.5:3001”;
    }
    }
  • 符号链接(symbolic link)默认从 sites-available 到 sites-enabled :
    sudo ln -s/etc/nginx/sites-available/default/etc/nginx/sites-enabled/default
  • 启动 nginx 须藤/etc/init.d/nginx 开始

  • 我得到的只是欢迎使用 nginx 如果您看到此页面,则 nginx 网络服务器已成功安装并正常工作。需要进一步配置。
  • 我也尝试在启用站点的情况下使用此配置

    上游项目{
    服务器 http://localhost:3001 ;
    }
    服务器 {
    听 80;
    }
    }

  • 但它产生相同的结果。请任何指导都会有所帮助。谢谢你。

    最佳答案

    尝试使用 proxy_pass 与本地主机,不带引号。

    假设您想要端口 3001 上的应用程序作为您的网站,您需要像这样配置它:

    location / {
    proxy_pass http://localhost:3001/;
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    proxy_set_header X-Forwarded-Proto $scheme;
    }

    此代码需要在 server 中您的 default 的 block 文件。

    它将传递来自位置 / 的所有流量(您的 Web 根目录)到端口 3001 .

    一个完整的示例如下所示:
    server {
    listen 80 default_server;
    listen [::]:80 default_server;

    server_name example.com;

    location / {
    proxy_pass http://localhost:3001/;
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    proxy_set_header X-Forwarded-Proto $scheme;
    }
    }

    解释:

    proxy_pass http://localhost:3001/;



    这会将所有流量传递到 port 3001 .

    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;



    这会将诸如发起调用的 IP 之类的信息传递给代理服务器。

    proxy_set_header X-Forwarded-Proto $scheme;



    这将转发请求的使用的 sheme/协议(protocol)信息。

    关于node.js - Nginx 配置错误反向代理在启动 nginx 时显示 "Welcome to nginx",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48252686/

    27 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com