为不同的端口配置nginx

时间:2016-10-06 04:50:50

标签: ruby-on-rails ruby ruby-on-rails-4 nginx passenger

我已经设置了我的nginx配置,我在同一个端口上运行两个网站。我的问题是我不想在打开我的网站时指定端口号。我在端口81上运行我的网站。我的问题是如果我有这两个网站abc.com:81和xyz.com:81。我需要在打开它们时包含端口号,我不想要,所以任何人都可以告诉我可能的解决方案.. < / p>

这是我的nginx配置

user  abc;
worker_processes  2;

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

events {
    worker_connections  1024;
}

http {
    include       /etc/nginx/mime.types;
    default_type  application/octet-stream;

    log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
                      '$status $body_bytes_sent "$http_referer" '
                      '"$http_user_agent" "$http_x_forwarded_for"';

    access_log  /var/log/nginx/access.log  main;
    sendfile        on;
    keepalive_timeout  65;

    passenger_root /usr/local/rvm/gems/ruby-2.2.3/gems/passenger-5.0.30;
    passenger_ruby /usr/local/rvm/gems/ruby-2.2.3/wrappers/ruby;
    passenger_max_pool_size 50;
    passenger_min_instances 5;
    passenger_max_instances_per_app 0;
    passenger_pool_idle_time 0;
    passenger_max_preloader_idle_time 0;
    passenger_app_env staging;
    passenger_friendly_error_pages on;

    server {
        listen       81 default_server;
        passenger_enabled on;

        server_name  abc.com;
        root         /var/www/project/current/public;

        location / {

        }

        error_page  404              /404.html;
        location = /40x.html {
           root /var/www/project/current/public;
        }

        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
           root /var/www/project/current/public;
        }
    }

    server {
    listen 81 ;
    passenger_enabled on;

    root  /var/www/new_project/current/public;
    server_name xyz.com;

    if (-f $document_root/system/maintenance.html)
    {
      rewrite  ^(.*)$  /system/maintenance.html last;
      break;
    }
    error_page   500 502 503 504  /500.html;
    location = /500.html
    {
      root /var/www/new_project/current/public;
    }
    error_page 404  /404.html;
    location = /404.html
    {
      root /var/www/new_project/current/public;
    }

  }

}

1 个答案:

答案 0 :(得分:0)

HTTP的默认端口是端口80.因此,如果您在端口80上侦听,则不需要在URL中指定端口号,因为如果未指定其他端口,则客户端将默认为端口80网址。

对于所有其他端口,有必要在URL中添加端口,因为客户端无法以其他方式找出要连接的端口。