【问题标题】:Nginx not working on port 80Nginx 无法在 80 端口上工作
【发布时间】:2016-05-11 04:01:21
【问题描述】:

我有一个在 localhost:1337 上运行的 node.js 服务器。我在sites_enabled 中创建了一个 nginx 站点文件。如果我转到 url admin.tvchatter.cn:1337,它正在工作,但如果我转到 url admin.tvchatter.cn,页面将显示“欢迎使用 nginx!”。 listen 80 似乎不起作用。文件内容是:

server {
    listen 80;
    server_name admin.tvchatter.cn;
    access_log /var/log/nginx/admin.tvchatter.cn.access.log;
    error_log /var/log/nginx/admin.tvchatter.cn.error.log;
    client_max_body_size 200m;

    gzip on;
    gzip_min_length 1k;
    gzip_buffers 16 64k;
    gzip_http_version 1.1;
    gzip_comp_level 6;
    gzip_types text/plain application/x-javascript text/javascript text/css application/xml;
    gzip_vary on;

    location /{
        proxy_pass http://127.0.0.1:1337;
        proxy_http_version 1.1;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection "upgrade";
    }
}

【问题讨论】:

  • "Welcome to nginx!" 意思是,nginx 正在使用端口 80,但它没有将流量从端口 80 重定向到端口 1337

标签: http nginx configuration


【解决方案1】:

您需要指定root 子句,默认情况下它包含值:/var/www/html/index.html 因此您会看到默认的 nginx 页面。我的配置如下:

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

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

【讨论】:

    【解决方案2】:

    查看/etc/nginx/sites-enabled/中的所有文件找到:

    proxy_pass http://example.com:8080;
    

    查看 nginx 使用 proxy_pass 到其他端口。

    如果是,请禁用它。

    【讨论】:

    • 启用站点时只有这个配置文件。
    • 尝试在proxy_set_header之后添加proxy_set_header Host $http_host;
    【解决方案3】:

    在我的情况下,代理只有在我使用另一个端口(如 90)时才能工作

    事实上,我在我的 /etc/nginx/nginx.conf 中导入了所有这样的 conf 文件

    include /etc/nginx/conf.d/*.conf;
    

    但我的文件与此文件夹中的现有文件冲突。我把它改成了这个,它起作用了:

    include /etc/nginx/conf.d/frontend.conf;
    

    【讨论】:

      猜你喜欢
      • 2015-12-03
      • 1970-01-01
      • 1970-01-01
      • 2015-07-23
      • 2017-11-19
      • 1970-01-01
      • 1970-01-01
      • 2022-01-25
      • 2013-10-14
      相关资源
      最近更新 更多