2017-10-20 11 views
0

私はnginxを初めて使用しています。 私は同じサーバー上に2つのドメインを持っています。Nginx - httpsでhttpベースのセカンダリドメインにアクセスするときにhttpsメインドメインにアクセス

https://main.site.com //Accessing a node server app on port 3000 

そして

http://secondary.site.com //Accessing a node server app on port 9000 

私はhttps://secondary.site.comにアクセスしようとすると、それは実際に私のhttps://main.site.comサーバコードにアクセスし、それ:http

https &別のすなわちに基づいて ワンhttps://secondary.site.comからここでhttp://secondary.site.com

は私のnginxの設定ファイルである:

user www-data; 
worker_processes auto; 
pid /run/nginx.pid; 

events { 
     worker_connections 768; 
     # multi_accept on; 
} 

http { 

     ## 
     # Basic Settings 
     ## 

     server { 
       listen  80; 
       server_name main.site.com; 
       location/{ 
         proxy_pass   http://main.site.com:3000; 
         proxy_set_header Host    $host; 
         proxy_set_header X-Real-IP  $remote_addr; 
         proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; 
         proxy_set_header X-Client-Verify SUCCESS; 
         proxy_set_header X-Client-DN  $ssl_client_s_dn; 
         proxy_set_header X-SSL-Subject $ssl_client_s_dn; 
         proxy_set_header X-SSL-Issuer  $ssl_client_i_dn; 
         proxy_read_timeout 1800; 
         proxy_connect_timeout 1800; 
         proxy_http_version 1.1; 
         proxy_set_header Upgrade $http_upgrade; 
         proxy_set_header Connection "upgrade"; 
       } 
     } 


     server { 
       listen    443; 
       server_name   main.site.com; 
       location/{ 
         proxy_pass   http://main.site.com:3000; 
         proxy_set_header Host    $host; 
         proxy_set_header X-Real-IP  $remote_addr; 
         proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; 
         proxy_set_header X-Client-Verify SUCCESS; 
         proxy_set_header X-Client-DN  $ssl_client_s_dn; 
         proxy_set_header X-SSL-Subject $ssl_client_s_dn; 
         proxy_set_header X-SSL-Issuer  $ssl_client_i_dn; 
         proxy_read_timeout 1800; 
         proxy_connect_timeout 1800; 
         proxy_http_version 1.1; 
         proxy_set_header Upgrade $http_upgrade; 
         proxy_set_header Connection "upgrade"; 
       } 
       ssl     on; 
       ssl_certificate   /etc/nginx/certificates/cert.pem; 
       ssl_certificate_key /etc/nginx/certificates/kry.pkey; 
       ssl_protocols  TLSv1 TLSv1.1 TLSv1.2; 
       ssl_ciphers !EDH:!AECDH:!ADH:!DSS:!RC4:ECDSA:HIGH:+3DES; 
       ssl_prefer_server_ciphers on; 
       ssl_ecdh_curve secp384r1; #courbe ECDH 
       add_header Strict-Transport-Security "max-age=31536000"; 
     } 

     server { 
       listen  80; 
       server_name secondary.site.com; 
       location/{ 
         proxy_pass   http://secondary.site.com:9000; 
         proxy_set_header Host    $host; 
         proxy_set_header X-Real-IP  $remote_addr; 
         proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; 
         proxy_set_header X-Client-Verify SUCCESS; 
         proxy_set_header X-Client-DN  $ssl_client_s_dn; 
         proxy_set_header X-SSL-Subject $ssl_client_s_dn; 
         proxy_set_header X-SSL-Issuer  $ssl_client_i_dn; 
         proxy_read_timeout 1800; 
         proxy_connect_timeout 1800; 
         proxy_http_version 1.1; 
         proxy_set_header Upgrade $http_upgrade; 
         proxy_set_header Connection "upgrade"; 
       } 
     } 



     # set client body size # 
     client_max_body_size 20M; 

     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; 

     ## 
     # SSL Settings 
     ## 

     ssl_protocols TLSv1 TLSv1.1 TLSv1.2; # Dropping SSLv3, ref: POODLE 
     ssl_prefer_server_ciphers on; 

} 
+0

'https:// secondary.site.com'の' server'ブロックがないので、 'nginx'はあなたの唯一の' https'サイトを使用します。 [このリンク](http://nginx.org/en/docs/http/server_names.html)が役立ちます。 –

+0

'https:// secondary.site.com'を' http:// secondary.site.com'にリダイレクトして、9000ポートのノードサーバーを使用できるようにします – StormTrooper

+0

'secondary.site .com'?ポート443で待機する 'secondary.site.com'の' server'ブロックを追加する必要があります。 –

答えて

0

あなたはHTTPSとHTTP上の二次にあなたのメイン・サイトをしたいので、あなたがこのsecondary.site.com

以下
user www-data; 
worker_processes auto; 
pid /run/nginx.pid; 

events { 
     worker_connections 768; 
     # multi_accept on; 
} 

http { 

     ## 
     # Basic Settings 
     ## 

     server { 
      listen 80 default; 
      server_name _; 
      return 301 http://secondary.site.com; 
     } 

     server { 
       listen 443 ssl; 
       server_name main.site.com; 
       ssl_certificate   /etc/nginx/certificates/cert.pem; 
       ssl_certificate_key /etc/nginx/certificates/kry.pkey; 
       ssl_protocols  TLSv1 TLSv1.1 TLSv1.2; 
       ssl_ciphers !EDH:!AECDH:!ADH:!DSS:!RC4:ECDSA:HIGH:+3DES; 
       ssl_prefer_server_ciphers on; 
       ssl_ecdh_curve secp384r1; #courbe ECDH 
       add_header Strict-Transport-Security "max-age=31536000"; 

       location/{ 
         proxy_pass   http://127.0.0.1:3000; 
         proxy_set_header Host    $host; 
         proxy_set_header X-Real-IP  $remote_addr; 
         proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; 
         proxy_set_header X-Client-Verify SUCCESS; 
         proxy_set_header X-Client-DN  $ssl_client_s_dn; 
         proxy_set_header X-SSL-Subject $ssl_client_s_dn; 
         proxy_set_header X-SSL-Issuer  $ssl_client_i_dn; 
         proxy_read_timeout 1800; 
         proxy_connect_timeout 1800; 
         proxy_http_version 1.1; 
         proxy_set_header Upgrade $http_upgrade; 
         proxy_set_header Connection "upgrade"; 
       } 
     } 

     server { 
       listen  80; 
       server_name secondary.site.com; 
       location/{ 
         proxy_pass   http://127.0.0.1:9000; 
         proxy_set_header Host    $host; 
         proxy_set_header X-Real-IP  $remote_addr; 
         proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; 
         proxy_set_header X-Client-Verify SUCCESS; 
         proxy_set_header X-Client-DN  $ssl_client_s_dn; 
         proxy_set_header X-SSL-Subject $ssl_client_s_dn; 
         proxy_set_header X-SSL-Issuer  $ssl_client_i_dn; 
         proxy_read_timeout 1800; 
         proxy_connect_timeout 1800; 
         proxy_http_version 1.1; 
         proxy_set_header Upgrade $http_upgrade; 
         proxy_set_header Connection "upgrade"; 
       } 
     } 



     # set client body size # 
     client_max_body_size 20M; 

     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; 

     ## 
     # SSL Settings 
     ## 

     ssl_protocols TLSv1 TLSv1.1 TLSv1.2; # Dropping SSLv3, ref: POODLE 
     ssl_prefer_server_ciphers on; 

} 

のようなものを使用することができる唯一のリッスンポート80、およびメインはポートhttpsのみ。私はセカンダリサイトに直接httpトラフィックのためのデフォルトのリダイレクトを持っています。しかし、あなたの要件に基づいてカスタマイズすることができます

関連する問題