【问题标题】:Welcome to Nginx page displays instead of actual webpage欢迎使用 Nginx 页面显示而不是实际网页
【发布时间】:2018-06-15 15:26:18
【问题描述】:

我正在 Ubuntu 服务器上开发一个 Ruby on Rails 项目。每当我尝试访问该应用程序时,总是会收到以下信息:

欢迎使用 nginx!

如果您看到此页面,则 nginx Web 服务器已成功安装并正在运行。需要进一步配置。

这是我在“sites_enabled”目录中的代码:

pstream unicorn_site {
    server unix:/tmp/unicorn.site.sock fail_timeout=0;
}

server {
    listen 80;

    client_max_body_size 4G;
    keepalive_timeout 10;

    error_page 500 502 504 /500.html;
    error_page 503 @503;

    server_name http://[ip_address];
    root /data/site/current/public;
    try_files $uri/index.html $uri @unicorn_site;

    location @unicorn_site {
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header Host $http_host;
        proxy_redirect off;

        proxy_pass http://unicorn_site;
        # limit_req zone=one;
        access_log /var/log/nginx/site.access.log;
        error_log /var/log/nginx/site.error.log;
    }

    location ^~ /assets/ {
        gzip_static on;
        expires max;
        add_header Cache-Control public;
    }

    location = /50x.html {
        root html;
    }

    location = /404.html {
        root html;
    }

    location @503 {
        error_page 405 = /system/maintenance.html;
        if (-f $document_root/system/maintenance.html) {
            rewrite ^(.*)$ /system/maintenance.html break;
        }
        rewrite ^(.*)$ /503.html break;
    }

    if ($request_method !~ ^(GET|HEAD|PUT|PATCH|POST|DELETE|OPTIONS)){
        return 405;
    }

    if (-f $document_root/system/maintenance.html) {
        return 503;
    }
}

我不确定问题出在哪里,因为该应用似乎具备正常运行所需的一切。我可以提供任何人需要的代码的任何部分。非常感谢您的帮助。

编辑:当我尝试加载页面时,我也总是收到此错误:

2018/06/15 15:39:10 [警告] 15280#0:服务器名称“http://[ip_address]”在 /etc/nginx/sites-enabled/site:14 中有可疑符号

编辑 2:这里是 nginx.conf

user www-data;
worker_processes 4;
pid /run/nginx.pid;

events {
    worker_connections 768;
}

http {

    ##
    # Basic Settings
    ##

    sendfile on;
    tcp_nopush on;
    tcp_nodelay on;
    keepalive_timeout 65;
    types_hash_max_size 2048;

    include /etc/nginx/mime.types;
    default_type application/octet-stream;

    ##
    # Logging Settings
    ##

    access_log /var/log/nginx/access.log;
    error_log /var/log/nginx/error.log;

    ##
    # Gzip Settings
    ##

    gzip on;
    gzip_disable "msie6";

    ##
    # Virtual Host Configs
    ##

    include /etc/nginx/conf.d/*.conf;
    include /etc/nginx/sites-enabled/*;
}

【问题讨论】:

    标签: ruby-on-rails ubuntu nginx unicorn


    【解决方案1】:

    移动'try_files $uri/index.html $uri @unicorn_site;'在位置/

    location / {
        try_files $uri/index.html $uri @unicorn_site;
    }
    

    【讨论】:

    • 相同的结果:/ 并且返回的任何错误始终相同 2018/06/15 15:39:10 [警告] 15280#0: 服务器名称“http://[ip_address]” /etc/nginx/sites-enabled/site:17 中有可疑符号
    【解决方案2】:

    server_name http://[ip_address]; 看起来不对。试试server_name example.com

    【讨论】:

    • 我使用的是 EC2 实例的 ip 地址,所以不幸的是使用网站名称不起作用
    • http:// 错误,请参阅文档nginx.org/en/docs/http/server_names.html
    • 我已将它从 EC2 更改为我的公共 DNS,没有 http://,我仍然看到欢迎屏幕
    • 你能把你的 /etc/nginx/nginx.conf 添加到问题中吗?可能是您没有像include /etc/nginx/sites-enabled/*; 那样包含启用站点的目录(在http 部分
    • sites-enabled 中的文件以.conf 结尾?只是检查每一种可能性。
    【解决方案3】:

    您是否配置了 ruby​​_passenger 线路?

    仔细遵循,您的部署应该会成功

    在此处选择您的 ubuntu 版本并继续

    https://gorails.com/deploy/ubuntu/16.04

    【讨论】:

      猜你喜欢
      • 2019-12-09
      • 2019-11-13
      • 2012-02-05
      • 1970-01-01
      • 2021-07-05
      • 2018-01-24
      • 2020-07-09
      • 2021-11-25
      • 2020-07-23
      相关资源
      最近更新 更多