2016-10-06 94 views
0

我已經設置了我的nginx配置,我在同一端口上運行兩個網站。我的問題是我不想指定端口號,只要我打開我的網站。我正在運行我的網站上端口81.我的問題是,如果我有這兩個網站abc.com:81和xyz.com:81。我需要包括端口號,同時打開它們,我不想要這樣任何人都可以告訴我可能的解決方案..配置nginx爲不同的端口

這裏是我的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; 
    } 

    } 

} 
+0

我想概念上你所做的是爲每個服務器配置一個「位置」,都在端口80「listen」塊內。即'/ server_a'和'/ server_b'。然後你會讓這些位置塊調用'proxy_pass'到你的其他端口。 –

回答

0

用於HTTP的默認端口爲端口80因此,如果偵聽端口80,你不需要因爲C的URL指定的端口號如果沒有在URL中指定其他端口,則用戶將默認爲端口80。

對於所有其他端口,有必要將端口添加到URL中,因爲客戶端沒有其他方式來找出以任何其他方式連接的端口。