欢迎使用Nginx页面显示而不是实际网页

时间:2018-06-15 15:26:19

标签: ruby-on-rails ubuntu nginx unicorn

我正在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 [warn] 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/*;
}

3 个答案:

答案 0 :(得分:0)

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

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

答案 1 :(得分:0)

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

答案 2 :(得分:0)

您是否配置了ruby_passenger线?

请仔细遵循此规则,并且您的部署应该成功

在那里选择你的ubuntu版本并继续

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