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?
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.
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