大网数据广告活动
服务器运维问答

nginx not serving site on cellular data connection

· 52CE 我爱测

I have a web server running nginx. If I access the website through a wifi connection, it loads the website. If I access it using LTE on my phone, it just shows the default "Welcome to nginx!" page Here is my site config file: ser…

问题原文

原帖链接 · andrewtweber · CC BY-SA 3.0

I have a web server running nginx. If I access the website through a wifi connection, it loads the website. If I access it using LTE on my phone, it just shows the default "Welcome to nginx!" page

Here is my site config file:

server {
    listen 80;
    listen 443 ssl;
    server_name {mysite.com};

    root   /path/to/public;
    index  index.php index.html index.htm;

    location / {
        try_files $uri $uri/ /index.php$is_args$args;
        include   /etc/nginx/conf.d/php-fpm;
    }

    ssl_certificate /etc/letsencrypt/live/{mysite.com}/fullchain.pem;
    ssl_certificate_key /etc/letsencrypt/live/{mysite.com}/privkey.pem;
}

已采纳解答

原帖链接 · MGP · CC BY-SA 3.0

That "Welcome" makes me suspect nginx is not reading the Host header in the request and the response is the default virtual host definition (which is the welcome message).

Remove your default vhost, on debian should be:

rm /etc/nginx/sites-enabled/default

Then add default_server to your site vhost definition:

listen 80 default_server;
listen 443 ssl default_server;

Reload: nginx -s reload

Test with curl:

curl -H "Host: mysite.com" mysite.com
curl mysite.com

The first request is sending the host header, the second does not. Both should return the same becase mysite.com is default now for ports 80 and 443 (one default_server for port).

This is like a brute force method, a smarter way would be debugging the requests, if all is correctly set up this should not happen.

摘自公开归档,保留原文语言,版式经整理,外部媒体与邮箱地址已移除。

资料来源与适用范围

资料来源
Server Fault
适用范围
以原帖系统、软件版本与发布日期为准(2016-11-30)
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY-SA 3.0

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。