我开发了rails app,它正在开发域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和虚拟主机,但我不知道如何:(
请帮助......
答案 0 :(得分:0)
将新的配置文件添加到/ 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;
}
}