如何将Nginx的Rails应用程序配置为子域? [英] How configure nginx for rails app as subdomain?

查看:81
本文介绍了如何将Nginx的Rails应用程序配置为子域?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我开发了Rails应用,并且可以在域mpm.head-system.com上运行 在我的VPS上,该应用程序位于/home/mobile_market path.

I developed rails app and it's working on domain mpm.head-system.com On my VPS the app is located in /home/mobile_market path.

这是nginx.conf:

This is 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/*;
}

这是启用了网站的默认配置:

This is sites-enabled/default config:

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

Everything works fine, and now I have a new rails app (redmine) on the same VPS.
Now I setup redmine on the same VPS and it works on the 3000 port - mpm.head-system.com:3000

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

How can I change nginx.conf to setup my redmine app on subdomain like - redmine.head-system.com ? How connect application, which running on other port, as subdomain? (because in /etc/hosts I can set IP without port only). I know that I need to use proxy_pass and virtual host, but I don't know how :(

请帮忙...

推荐答案

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

Add new confing file to /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;
  }

}

这篇关于如何将Nginx的Rails应用程序配置为子域?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆