nginx 使用 https 配置(非标准端口)
实现效果:访问 http://your_domain.com:9092 自动跳转到 https://your_domain.com:9093
#首先可以使用阿里的免费ssl 证书
mkdir /etc/nginx/cert
#下载证书到 /etc/nginx/cert
#假设您的证书为:your_domain.com.pem 和 your_domain.com.key
vi /etc/nginx/conf.d/9092.conf
内容如下
server { listen 9092; server_name your_domain.com; rewrite ^(.*)$ https://$host:9093$1; location / { index index.php index.html index.htm; } } server { listen 9093 ssl; server_name your_domain.com; root /var/www/html/vpn; index index.php index.html index.htm; ssl_certificate /etc/nginx/cert/your_domain.com.pem; ssl_certificate_key /etc/nginx/cert/your_domain.com.key; ssl_session_timeout 5m; ssl_ciphers ECDHE-RSA-AES128-GCM-SHA256:ECDHE:ECDH:AES:HIGH:!NULL:!aNULL:!MD5:!ADH:!RC4; ssl_protocols TLSv1.1 TLSv1.2 TLSv1.3; ssl_prefer_server_ciphers on; location / { try_files $uri $uri/ =404; } error_page 404 /404.html; error_page 500 502 503 504 /50x.html; location = /50x.html { root /usr/share/nginx/html; } location ~ \.php$ { try_files $uri =404; fastcgi_pass unix:/var/run/php-fpm/php-fpm.sock; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; include fastcgi_params; } }
防火墙开放 9092 和 9093 端口
重启nginx
systemctl reload nginx