nginx配置http请求跳转到https
发布日期:2021-05-14 01:22:02 浏览次数:20 分类:精选文章

本文共 2628 字,大约阅读时间需要 8 分钟。

Nginx��� HTTPS ��������� http ��� https ���������

��������� Nginx ������������ ������ ��������� HTTPS��������������������� ������ ������ http ������ ��� ������ ��������������������� Nginx ��� ������ ��������� http ��� https ��� ��� ��� ������������ ��� ������ ��� ������ ������ ��� ���������������

1. ������ Nginx ������

������ Nginx ������ ������ ��������������� Unix/Linux ������ ������ ������������������ /etc/nginx/sites-enabled/��� ������ ������ ��������������� server ������������ ������ listener ��������������������� http port���80��� ������ ��� SSL/TLS port���443������

server {
listen 443 ssl; # ������ 80 ��� 443
ssl on;
ssl_certificate /path/to/cert.pem; # ������ SSL ������ ������ ������
ssl_key_file /path/to/server.key; # ������������ ������
ssl_protocols TLSv1.2 TLSv1.3; # ������������������ ��� ������ ��� SSL/TLS ������
ssl_ciphers ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES128-SHA256:ECDHE-RSA-AES128-SHA256; # ��������������������� ������
add_header X-Frame-Options "DENY"; # ������ ��� XSS ������
add_header X-Content-Type-Options "nosniff"; # ������ ��������� ������
}

2. HTTP ��� HTTPS ���������

������ ������ http ��� https ��� ��� ������������ ������������ navbar ������ ���������errorCodeMiddleware ���������� ���������

location / {
return 301 https://$server_name$request_uri;
}

������������ ��� ������ ��������� return ������������������

server {
listen 80; # ��������������� http port
server_name example.com;
access_log off;
}
server {
listen 443 ssl;
server_name example.com;
ssl on;
ssl_certificate /path/to/cert.pem;
ssl_key_file /path/to/server.key;
location / {
return 301 https://$server_name$request_uri;
}
}

3. ���������������

������ ������ https ��� ������ ������������ ��������������� ������������ ������ ��� ��������� HTTPS ��� ���������

firewall-cmd --zone=public --add-port=443/tcp

4. ������

  • ������ ������ ������ ������������������ ������ ��� ������ ������ ��� HTTPS���
  • ������ curl ������ ���������
curl -I http://example.com

������ ������ ������ ������ 301 Moving Permanently������������ ��� ������ ��� ��� ��� ��� ��� HTTPS���

��������������� ������ ��������� ������ ������ ������ ������������������ ��������� ��� ������ ��������������� ������ ��� ������ ��� ������ ��������� ������ ��������������� ������ ��������� ��� TLS ���������

��������������������������� ������ http ������ ������ ������ ������������ ������ ��������� ��� ��� ��� ��� HTTPS ���������

��������� ��� ��������� ������ ������ ��������������� ��� ������ ��� ��������bicalse lettuce ������ ��� ������

上一篇:Qt设置程序的字符集
下一篇:关于qss设置窗口的背景图片

发表评论

最新留言

第一次来,支持一个
[***.219.124.196]2025年04月12日 09时17分03秒