0. Introduction
When I was in high school, I built a campus community website.
The website is in mainland China, and the domain name has not been filed, but it has never been blocked, which is also very magical.
However, some students reported to me that users of China Unicom will be blocked by the record when they open my website.
So I used port 81. When it is added, it prompts that the domain name already exists. As a last resort, I parsed a second-level domain name and used port 81 to access it.
But this way, the website can only be accessed via HTTP. By modifying the configuration file, the non-standard port HTTPS is implemented, but it will be redirected to port 443 by "forced HTTPS".
Therefore, this article will introduce the scheme of modifying and configuring Nginx files to achieve HTTPS access to non-standard ports.
1, add port
In the Bt panel, there are many ports that cannot be added directly, such as 8888 and 8080. So you can add in the configuration file:
1 | listen 8080; |
Bind port 8080 as the HTTP port of the website.
To use HTTPS, add the following after configuring the SSL certificate:
1 | listen 8888 ssl http2; |
Bind port 8888 as the HTTPS port of the website.
2. Modify the mandatory HTTPS content
After enabling HTTPS, it will automatically add:
1 | #HTTP_TO_HTTPS_START if ($server_port !~ 443){ rewrite ^(/.*)$ https://$host$1 permanent; } #HTTP_TO_HTTPS_END |
The principle is: redirect the non-443 port to the 443 port.
can be changed to
Comment first then view it after your comment is approved. Join QQ Group to display all hidden texts.
The principle is: only redirect port 80 to port 443, so that HTTPS access to special ports will not be affected.
3. Subdomain HTTPS access
Copy the configuration file for the SSL-configured site:
Comment first then view it after your comment is approved. Join QQ Group to display all hidden texts.
Go to the configuration file segment corresponding to the subdomain name.
and follow the above in
1 | listen 80; |
add under
1 | listen 443 ssl http2; |
HTTPS access to subdomains can be achieved.
If you need to enable mandatory HTTPS, just copy the corresponding configuration file fragment.
Nginx non-standard port or subdomain to enable SSL
Comments