Nginx在80端口无法工作

3

我有一个运行在localhost:1337的node.js服务器。我已经在sites_enabled中创建了一个nginx站点文件。如果我访问urladmin.tvchatter.cn:1337,它可以正常工作,但是如果我访问urladmin.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端口。 - undefined
3个回答

1

检查 /etc/nginx/sites-enabled/ 中的所有文件,查找:

proxy_pass http://example.com:8080;

想要查看nginx如何使用proxy_pass到其他端口。

如果是的话,请禁用它。


在sites-enabled目录中只有这个配置文件。 - undefined
proxy_set_header行之后尝试添加proxy_set_header Host $http_host; - undefined

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;

0
在我的情况下,代理只有在我使用另一个端口(如90)时才起作用。
实际上,我是这样导入所有配置文件的:/etc/nginx/nginx.conf
include /etc/nginx/conf.d/*.conf;

但是我的文件与此文件夹中现有的文件冲突。我将其更改为以下内容,然后它就可以正常工作了:

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

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接