Technical Blog | 技術博客

易,窮則變,變則通,通則久。是以自天佑之,吉無不利。

[Original] Nginx sets IPV6 Listening and 301 redirects and enables SSL forced jumps

Introduction

Sometimes you will encounter such a problem:

1. My server has IPV6 but cannot access it via IPV6 (accessible only via IPV4).
2. Nginx does not listen to IPV6, so users using IPV6 cannot access my website. As a developer I want to make IPV6 available, I need it. (The App Store requires the app to support IPV6).
3. I need to redirect cxthhhhh.com to www.cxthhhhh.com and I want to force HTTP (80) to jump to HTTPS (443) for the website.
4. [Test] The aaPanel panel itself supports IPV6 support (there is no problem in theory, no test, please feedback, do not play in the official environment)

如果你来自于中文社区,请点击这里

Let’s start

1. I want to enable IPV6 listening for Nginx

①. First you need to configure IPV6 for your server. You can only use it if you have an IPV6 address.
IPV6 tutorial for any server configuration (provided by tech.cxthhhhh.com)
[Original] Manually configure IPV6 for any server

②. Check if Nginx has IPV6 support installed.
SSH terminal input: [nginx -V], check if there is [–with-ipv6] output, which means that the IPV6 module has been installed.

③. Edit the website configuration file.
Find
listen 80;
listen 443 ssl http2;
Replace with
listen 80;
listen [::]:80;
listen 443 ssl http2;
listen [::]:443 ssl http2;
Restart Nginx

④. Now you can access your website via IPV6.

2. Force SSL to be enabled for my site

1. Add the following to the website profile
if ($server_port !~ 443){
rewrite ^(/.*)$ https://$host$1 permanent;
}

2. Restart Nginx, clear the browser cache, and you will find that the HTTP (80) website automatically jumps to HTTPS (443).

3. I want to redirect website 301 to a subdomain with www

①. Add the following to the website profile
if ($host ~ '^cxthhhhh.com'){
return 301 https://www.cxthhhhh.com$request_uri;
}
*You need to modify cxthhhhh.com for your domain name

②. Restart Nginx, clear the browser cache, and you will find that the 301 redirect has taken effect.

4. Enable IPV6 support for the aapanel panel itself (*Pagoda panel itself. For the Nginx website access, please see the first one)

python -c "import socket,SocketServer,CGIHTTPServer;SocketServer.TCPServer.address_family=socket.AF_INET6;CGIHTTPServer.test()" 8888

Then you can access your pagoda panel through IPV6, remember to change port 8888 to your own.

Great, you have already learned, go try it.

If you need additional help, here is a recommended article.
[Original] A complete solution for new servers (system installation, site environment configuration, network and system optimization, full backup and restore migration, desktop environment, tool collection)

[Technical Blog | Technology Blog] Telegram exchange channel: https://t.me/me_share (TG discussion group please pay attention to TG channel top message)

This article was posted on the [CXT] Technical Blog | 技術博客, if you need to forward the share, please indicate the source.

[Original] Nginx sets IPV6 snooping and 301 redirects and enables SSL forced jumps

点赞