【问题标题】:How configure nginx for rails app as subdomain?如何将 Rails 应用程序的 nginx 配置为子域?
【发布时间】:2014-07-22 21:53:05
【问题描述】:

我开发了 rails 应用程序,它在域 mpm.head-system.com 上工作 在我的 VPS 上,该应用位于 /home/mobile_market path

这是 nginx.conf:

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

events { worker_connections 1024; }

http {
    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;

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

    gzip on;
    gzip_disable "msie6";
    gzip_types text/plain text/xml text/css text/comma-separated-values;
        upstream app_server { 
        server 127.0.0.1:8080 fail_timeout=0;
    }

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

这是启用站点/默认配置:

server {
    listen   80;
    root /home/mobile_market/public/;
    server_name mpm.head-system.com;
    index index.htm index.html;

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

  location ~* ^.+\.(jpg|jpeg|gif|png|ico|zip|tgz|gz|rar|bz2|doc|xls|exe|pdf|ppt|txt|tar|mid|midi|wav|bmp|rtf|mp3|flv|mpeg|avi)$ {
        try_files $uri @app;
    }

    location @app {
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header Host $http_host;
        proxy_redirect off;
        proxy_pass http://app_server;
  }

}

一切正常,现在我在同一个 VPS 上有了一个新的 rails 应用程序(redmine)。
现在我在同一个 VPS 上设置 redmine,它可以在 3000 端口上运行 - mpm.head-system.com:3000

如何更改 nginx.conf 以在子域上设置我的 redmine 应用程序 - redmine.head-system.com ? 如何连接在其他端口上运行的应用程序作为子域? (因为在 /etc/hosts 我只能设置没有端口的 IP)。 我知道我需要使用 proxy_pass 和虚拟主机,但我不知道如何:(

请帮忙...

【问题讨论】:

    标签: ruby-on-rails nginx subdomain config proxypass


    【解决方案1】:

    添加新的配置文件到 /etc/nginx/sites-enabled: redmine.config

    server {
        listen   80;
        root /home/redmine/;
        server_name redmine.head-system.com;
        index index.htm index.html;
    
        location / {
            try_files $uri/index.html $uri.html $uri @app;
        }
    
      location ~* ^.+\.(jpg|jpeg|gif|png|ico|zip|tgz|gz|rar|bz2|doc|xls|exe|pdf|ppt|txt|tar|mid|midi|wav|bmp|rtf|mp3|flv|mpeg|avi)$ {
            try_files $uri @app;
        }
    
        location @app {
            proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
            proxy_set_header Host $http_host;
            proxy_redirect off;
            proxy_pass http://localhost:3000;
      }
    
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2011-01-23
      • 2011-06-28
      • 1970-01-01
      • 2012-03-31
      • 2017-09-19
      • 1970-01-01
      • 2021-04-01
      相关资源
      最近更新 更多