Nginx 初始安装后不显示欢迎页面

Posted

技术标签:

【中文标题】Nginx 初始安装后不显示欢迎页面【英文标题】:Nginx not displaying welcome page after initial installation 【发布时间】:2018-08-01 17:53:34 【问题描述】:

在 Ubuntu 17 上安装后我没有看到欢迎页面。在 Chrome 上显示“此页面无法正常工作..ERR_EMPTY_RESPONSE”

以下是我的设置:

    防火墙被禁用

sudo ufw 禁用 防火墙在系统启动时停止并禁用

    服务已启动并正在运行

    nginx.service - A high performance web server and a reverse proxy server
       Loaded: loaded (/lib/systemd/system/nginx.service; enabled; vendor preset: enabled)
      Drop-In: /etc/systemd/system/nginx.service.d
               └─override.conf
       Active: active (running) since Thu 2018-02-22 10:22:31 UTC; 1min 6s ago
      Process: 1356 ExecStartPost=/bin/sleep 0.1 (code=exited, status=0/SUCCESS)
      Process: 1270 ExecStart=/usr/sbin/nginx -g daemon on; master_process on; (code=exited, status=0/SUCCESS)
      Process: 1167 ExecStartPre=/usr/sbin/nginx -t -q -g daemon on; master_process on; (code=exited, status=0/SUCCESS)
     Main PID: 1339 (nginx)
        Tasks: 2
       Memory: 9.2M
          CPU: 32ms
       CGroup: /system.slice/nginx.service
               ├─1339 nginx: master process /usr/sbin/nginx -g daemon on; master_process on
               └─1345 nginx: worker process                           
    
    Feb 22 10:22:29 jitsinew systemd[1]: Starting A high performance web server and a reverse proxy server...
    Feb 22 10:22:31 jitsinew systemd[1]: Started A high performance web server and a reverse proxy server.
    

    所有配置都是默认的,如下:

    
    user www-data;
    worker_processes auto;
    pid /run/nginx.pid;
    include /etc/nginx/modules-enabled/*.conf;
    
    events 
        worker_connections 768;
        # multi_accept on;
    
    
    http 
    
        ##
        # Basic Settings
        ##
    
        sendfile on;
        tcp_nopush on;
        tcp_nodelay on;
        keepalive_timeout 65;
        types_hash_max_size 2048;
        # server_tokens off;
    
        # server_names_hash_bucket_size 64;
        # server_name_in_redirect off;
    
        include /etc/nginx/mime.types;
        default_type application/octet-stream;
    
        ##
        # SSL Settings
        ##
    
        ssl_protocols TLSv1 TLSv1.1 TLSv1.2; # Dropping SSLv3, ref: POODLE
        ssl_prefer_server_ciphers on;
    
        ##
        # Logging Settings
        ##
    
        access_log /var/log/nginx/access.log;
        error_log /var/log/nginx/error.log;
    
        ##
        # Gzip Settings
        ##
    
        gzip on;
        gzip_disable "msie6";
    
        # gzip_vary on;
        # gzip_proxied any;
        # gzip_comp_level 6;
        # gzip_buffers 16 8k;
        # gzip_http_version 1.1;
        # gzip_types text/plain text/css application/json application/javascript text/xml application/xml application/xml+rss text/javascript;
    
        ##
        # Virtual Host Configs
        ##
    
        include /etc/nginx/conf.d/*.conf;
        include /etc/nginx/sites-enabled/*;
    
    

    /etc/nginx/sites-enabled/下有一个名为default的文件,配置如下:

    server 
    listen 80 default_server;
    listen [::]:80 default_server;
    root /var/www/html;
    server_name _;
    location / 
        # First attempt to serve request as file, then
        # as directory, then fall back to displaying a 404.
        try_files $uri $uri/ =404;
    
    
    

有什么想法吗?

【问题讨论】:

请添加文件include /etc/nginx/sites-enabled/*;server 部分中的内容 有一个名为default的文件,其实我初次安装后并没有做任何改动,配置如下: server listen 80 default_server;听 [::]:80 默认服务器;根 /var/www/html;服务器名称 _; location / # 首先尝试将请求作为文件,然后 # 作为目录,然后返回显示 404。try_files $uri $uri/ =404; 你检查过 nginx 日志文件吗? @Evert,错误日志文件为空 @RidgeA,我只是补充了主题#4中的默认文件 【参考方案1】:

添加

index index.html index.htm index.nginx-debian.html;

server 
listen 80 default_server;
listen [::]:80 default_server;
root /var/www/html;
index index.html index.htm index.nginx-debian.html;
server_name _;
location / 
    # First attempt to serve request as file, then
    # as directory, then fall back to displaying a 404.
    try_files $uri $uri/ =404;


【讨论】:

【参考方案2】:

我遇到了同样的问题,但我只是通过键入 service nginx start 来启动服务器,然后在我的浏览器中键入 localhost 来启动 nginx,它就可以工作了。

【讨论】:

以上是关于Nginx 初始安装后不显示欢迎页面的主要内容,如果未能解决你的问题,请参考以下文章

Nginx 显示欢迎页面/403 错误而不是主页

Docker compose with nginx 不断显示欢迎页面

Firebase 托管在部署 Angular 6 应用程序后显示欢迎页面?

直接从ip地址访问时删除默认的nginx欢迎页面

NuxtJS 有时会提供欢迎页面

XAMPP 一直显示仪表板/欢迎页面而不是配置页面