首頁  >  問答  >  主體

nginx - Ngnix怎麼在一個Server裡同時使用http和https

我現在的nginx設定是

server {
  listen 80;
  ...
}

server {
  listen 443;
  ssl on;
  ...
}

但是這兩個Server裡的其他配置都是一模一樣的,看的我噁心死了。 。 。有沒有辦法,讓同一個Server監聽80和443,然後同時使用http和https的?

巴扎黑巴扎黑2712 天前607

全部回覆(3)我來回復

  • 淡淡烟草味

    淡淡烟草味2017-05-16 17:31:59

    雷雷

    回覆
    0
  • 漂亮男人

    漂亮男人2017-05-16 17:31:59

    除了樓上的方法,還有一個辦法
    因為流量多之後都會有集群,會使用upsteam 。可以將443和80都轉到80埠上。

    回覆
    0
  • ringa_lee

    ringa_lee2017-05-16 17:31:59

    https://ma.ttias.be/force-redirect-http-https-custom-port-nginx/

    server {
    listen 1234 ssl;
    server_name your.site.tld;
    ssl on;
    ...
    error_page 497 https://$host:1234$
    error_page 497 https://$host:1234$request_uri;
    自訂連接埠,強制跳轉可以用

    回覆
    0
  • 取消回覆