新安装的 nginx 不提供默认页面 [英] Freshly installed nginx not serving default page

查看:83
本文介绍了新安装的 nginx 不提供默认页面的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我刚刚在一个新的 ubuntu 实例上安装了 nginx.看起来 nginx 正在运行,这里是进程:

root 2062 0.0 0.1 85868 1340 ?ss 01:13 0:00 nginx:主进程/usr/sbin/nginxwww-data 2063 0.0 0.1 86212 1768 ?S 01:13 0:00 nginx:工作进程www-data 2064 0.0 0.1 86212 1768 ?S 01:13 0:00 nginx:工作进程www-data 2065 0.0 0.1 86212 1768 ?S 01:13 0:00 nginx:工作进程www-data 2066 0.0 0.1 86212 1768 ?S 01:13 0:00 nginx:工作进程ubuntu 2120 0.0 0.0 10460 932 pts/0 S+ 01:34 0:00 grep --color=auto nginx

这里还有 sudo nstat -plnt

tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN 1076/sshdtcp 0 0 0.0.0.0:80 0.0.0.0:* 听 2062/nginxtcp6 0 0 :::22 :::* 听 1076/sshdtcp6 0 0 :::80 :::* 听 2062/nginx

但是当我访问我的公共 IP 地址(我没有配置任何站点)时,我的浏览器超时并且不显示默认的 nginx 页面.

nginx 日志中没有错误并且 sudo nginx -t 看起来不错.我按照一些教程安装并启动了它,但一切都说它应该立即为默认主页提供服务.

这是我的/etc/nginx/sites-enabled

服务器{听 80 default_server;听 [::]:80 default_server ipv6only=on;根目录/usr/share/nginx/html;index index.html index.htm;server_name 本地主机;地点/{try_files $uri $uri/=404;}}

解决方案

我在 Digital Ocean 上设置新服务器并遵循他们的教程(包括启用简单防火墙)后遇到了这个问题.但是教程没有提到启用http和https流量,你必须这样做!

https://www.digitalocean.com/community/tutorials/how-to-set-up-an-ubuntu-20-04-server-on-a-digitalocean-droplet

https://www.digitalocean.com/community/tutorials/how-to-set-up-a-firewall-with-ufw-on-ubuntu-20-04

sudo ufw 允许 http须藤 ufw 允许 https

I just installed nginx on a new ubuntu instance. It looks like nginx is running, here are the processes:

root      2062  0.0  0.1  85868  1340 ?        Ss   01:13   0:00 nginx: master process /usr/sbin/nginx
www-data  2063  0.0  0.1  86212  1768 ?        S    01:13   0:00 nginx: worker process
www-data  2064  0.0  0.1  86212  1768 ?        S    01:13   0:00 nginx: worker process
www-data  2065  0.0  0.1  86212  1768 ?        S    01:13   0:00 nginx: worker process
www-data  2066  0.0  0.1  86212  1768 ?        S    01:13   0:00 nginx: worker process
ubuntu    2120  0.0  0.0  10460   932 pts/0    S+   01:34   0:00 grep --color=auto nginx

Also here is sudo nstat -plnt

tcp        0      0 0.0.0.0:22              0.0.0.0:*               LISTEN      1076/sshd       
tcp        0      0 0.0.0.0:80              0.0.0.0:*               LISTEN      2062/nginx      
tcp6       0      0 :::22                   :::*                    LISTEN      1076/sshd       
tcp6       0      0 :::80                   :::*                    LISTEN      2062/nginx  

But when I go to my public ip address (I don't have any sites configured) my browser times out and the default nginx page is not displayed.

There are no errors in the nginx log and sudo nginx -t looks fine. I followed some tuts to get it installed and started, but everyhthing says it should immediately serve the default homepage.

Here is what is in my /etc/nginx/sites-enabled

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

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

    server_name localhost;

    location / {
            try_files $uri $uri/ =404;
    }
}

解决方案

I had this problem after I set a new server up on Digital Ocean and followed their tutorial which included enabling Uncomplicated Firewall. But the tutorial didn't mention enabling http and https traffic, which you have to do!

https://www.digitalocean.com/community/tutorials/how-to-set-up-an-ubuntu-20-04-server-on-a-digitalocean-droplet

https://www.digitalocean.com/community/tutorials/how-to-set-up-a-firewall-with-ufw-on-ubuntu-20-04

sudo ufw allow http
sudo ufw allow https

这篇关于新安装的 nginx 不提供默认页面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆