简体   繁体   English

Nginx在Rails应用中显示http请求的“欢迎使用nginx”

[英]Nginx shows “Welcome to nginx” for http request in Rails app

I am using following nginx configurations: 我正在使用以下nginx配置:

user www-data;
worker_processes  1;

error_log  /var/log/nginx/error.log;
pid        /var/run/nginx.pid;

events {
    worker_connections  1024;
    # multi_accept on;
}

http {
    include       /etc/nginx/mime.types;

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

    sendfile        on;
    #tcp_nopush     on;

    #keepalive_timeout  0;
    keepalive_timeout  65;
    tcp_nodelay        on;

    gzip  on;
    gzip_disable "MSIE [1-6]\.(?!.*SV1)";

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

    upstream myapp.co {
      server 127.0.0.1:8080;
    }


    server{
      listen 80;
      server_name myapp.co;
      rewrite ^ https://myapp.co$request_uri? permanent;
    }

    server {
      listen  443 ssl;
      server_name  myapp.co;
      root /home/deployer/myapp/public;

      ssl on;
      ssl_certificate      /etc/nginx/certs/myapp.co.crt;
      ssl_certificate_key  /etc/nginx/certs/myapp.co.private.key;

      #server_name myapp.co _;
      #root /home/deployer/myapp/public;

      location / {
        proxy_set_header X_FORWARDED_PROTO $scheme;
        proxy_set_header Host $http_host;
        proxy_set_header   X-Forwarded-For   $proxy_add_x_forwarded_for;
        proxy_set_header   X-Forwarded-Proto $scheme;
        proxy_set_header   Host              $http_host;
        proxy_set_header   X-Real-IP         $remote_addr;
        proxy_set_header   CLIENT_IP         $remote_addr;

        proxy_redirect http:// https://;
        if (!-f $request_filename) {
          proxy_pass http://myapp.co;
          break;
        }
        if (-f $document_root/system/maintenance.html) {
          return 503;
        }
      }
   }
}

The issue: when I load http://www.myapp.co , I get the error message 问题:加载http://www.myapp.co ,出现错误消息

Welcome to nginx

But if I set to the browser 但是如果我设置为浏览器

https://www.myapp.co
https://myapp.co
http://myapp.co

Everything is working well. 一切都很好。

How can I fix up the proper displaying of the Rails app also for the request http://www.myapp.co ? 如何为请求http://www.myapp.co修复Rails应用程序的正确显示?

I am quite amateur with setting up of nginx, so I'll be grateful for every advice. 我对设置Nginx相当业余,所以我将为您的每条建议而感激。

Thank you 谢谢

我认为,您应该这样设置server_name(在两个server部分中):

server_name myapp.co www.myapp.co;

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM