Nginx重定向到https和www

Nginx重定向到https和www

𝓓𝓸𝓷 Lv6

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
server {

listen 80;
server_name zhangdong.me www.zhangdong.me;
return 301 https://www.zhangdong.me$request_uri;
}


server {

listen 443 ssl;
server_name zhangdong.me;
ssl_certificate /etc/nginx/ssl/zhangdong.me.cer;
ssl_certificate_key /etc/nginx/ssl/zhangdong.me.key;
ssl_stapling on;
ssl_stapling_verify on;
return 301 https://www.zhangdong.me$request_uri;
add_header Strict-Transport-Security "max-age=31536000";
error_log /var/log/nginx/error.log;
access_log /var/log/nginx/access.log combined;

}


server {

listen 443 ssl;
server_name www.zhangdong.me;
ssl_certificate /etc/nginx/ssl/zhangdong.me.cer;
ssl_certificate_key /etc/nginx/ssl/zhangdong.me.key;
ssl_stapling on;
ssl_stapling_verify on;
add_header Strict-Transport-Security "max-age=31536000";
error_log /var/log/nginx/error.log;
access_log /var/log/nginx/access.log combined;


location / {

try_files $uri $uri/ /index.php?$args;
root /var/www/html;
index index.html index.htm;

}

location /img/ {

alias /home/admin/images;
try_files $uri $uri/ =404;

}


error_page 404 /404.html;
location = /404.html {
root /var/www/html;
internal;
}

}
  • Title: Nginx重定向到https和www
  • Author: 𝓓𝓸𝓷
  • Created at : 2024-06-27 14:00:39
  • Updated at : 2024-07-20 05:15:41
  • Link: https://www.zhangdong.me/nginx-redirect-to-www-https.html
  • License: This work is licensed under CC BY-NC-SA 4.0.
评论