nginx配置
2022-10-10 20:47:50 # other

/etc/nginx/sites-available/default

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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
##
# You should look at the following URL's in order to grasp a solid understanding
# of Nginx configuration files in order to fully unleash the power of Nginx.
# https://www.nginx.com/resources/wiki/start/
# https://www.nginx.com/resources/wiki/start/topics/tutorials/config_pitfalls/
# https://wiki.debian.org/Nginx/DirectoryStructure
#
# In most cases, administrators will remove this file from sites-enabled/ and
# leave it as reference inside of sites-available where it will continue to be
# updated by the nginx packaging team.
#
# This file will automatically load configuration files provided by other
# applications, such as Drupal or Wordpress. These applications will be made
# available underneath a path with that package name, such as /drupal8.
#
# Please see /usr/share/doc/nginx-doc/examples/ for more detailed examples.
##

# Default server configuration
#

server {
listen 80;

#填写绑定证书的域名
server_name jiangpenghui.cn www.jiangpenghui.cn;

#跳转www
if ($host != 'www.jiangpenghui.cn' ) {
rewrite ^/(.*)$ https://www.jiangpenghui.cn/$1 permanent;
}

index index.html index.htm index.php;
#(第一种)把http的域名请求转成https
#return 301 https://www.jiangpenghui.cn$request_uri;

#(第二种)强制将http的URL重写成https
rewrite ^(.*) https://www.jiangpenghui.cn$1 permanent;
}

#HTTPS使用SSL访问的配置
server {
#SSL使用443端口
listen 443 ssl;

#SSL证书绑定的单域名
server_name www.jiangpenghui.cn;

#证书pem文件
ssl_certificate /usr/local/ssl_info/jiangpenghui.cn_bundle.pem;

#证书key文件
ssl_certificate_key /usr/local/ssl_info/jiangpenghui.cn.key;

#缓存SSL握手产生的参数和加密密钥的时长
ssl_session_timeout 5m;

#使用的加密套件的类型
ssl_ciphers ECDHE-RSA-AES128-GCM-SHA256:ECDHE:ECDH:AES:HIGH:!NULL:!aNULL:!MD5:!ADH:!RC4;

#表示使用的TLS协议的类型
ssl_protocols TLSv1 TLSv1.1 TLSv1.2;

#加密套件优先选择服务器的加密套件
ssl_prefer_server_ciphers on;

#spa应用配置
location / {
root /var/www/hexo; #配置应用的文件夹
index index.html index.htm;
try_files $uri $uri/ /index.html;
}
}

# Virtual Host configuration for example.com
#
# You can move that to a different file under sites-available/ and symlink that
# to sites-enabled/ to enable it.
#
#server {
# listen 80;
# listen [::]:80;
#
# server_name example.com;
#
# root /var/www/example.com;
# index index.html;
#
# location / {
# try_files $uri $uri/ =404;
# }
#}