Home  >  Q&A  >  body text

nginx - How does Ngnix use http and https at the same time in a server?

My current nginx configuration is

server {
  listen 80;
  ...
}

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

But the other configurations in the two servers are exactly the same, which makes me sick to death. . . Is there any way to make the same server listen to 80 and 443, and then use http and https at the same time?

巴扎黑巴扎黑2712 days ago599

reply all(3)I'll reply

  • 淡淡烟草味

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

    listen              80;
    listen              443 ssl;

    reply
    0
  • 漂亮男人

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

    In addition to the method above, there is another way
    Because there will be a cluster when there is a lot of traffic, upsteam will be used. You can transfer both 443 and 80 to port 80.

    reply
    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$request_uri;
    ...
    }

    Customized port, forced jump can be used

    reply
    0
  • Cancelreply