/
nginx.conf
179 lines (152 loc) · 5.91 KB
/
nginx.conf
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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
user www-data;
worker_processes auto;
worker_rlimit_nofile 20480;
pid /run/nginx.pid;
include /etc/nginx/modules-enabled/*.conf;
events {
worker_connections 10240;
# multi_accept on;
}
http {
##
# Basic Settings
##
sendfile on;
tcp_nopush on;
tcp_nodelay on;
keepalive_timeout 65;
types_hash_max_size 2048;
server_tokens off;
server_names_hash_bucket_size 128;
# server_name_in_redirect off;
include /etc/nginx/mime.types;
default_type application/octet-stream;
##
# SSL Settings
##
ssl_protocols TLSv1 TLSv1.1 TLSv1.2; # Dropping SSLv3, ref: POODLE
ssl_prefer_server_ciphers on;
ssl_session_cache shared:SSL:5m;
ssl_session_timeout 30m;
ssl_ciphers 'ECDHE-RSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES256-GCM-SHA384:ECDHE-ECDSA-AES256-GCM-SHA384:DHE-RSA-AES128-GCM-SHA256:DHE-DSS-AES128-GCM-SHA256:kEDH+AESGCM:ECDHE-RSA-AES128-SHA256:ECDHE-ECDSA-AES128-SHA256:ECDHE-RSA-AES128-SHA:ECDHE-ECDSA-AES128-SHA:ECDHE-RSA-AES256-SHA384:ECDHE-ECDSA-AES256-SHA384:ECDHE-RSA-AES256-SHA:ECDHE-ECDSA-AES256-SHA:DHE-RSA-AES128-SHA256:DHE-RSA-AES128-SHA:DHE-DSS-AES128-SHA256:DHE-RSA-AES256-SHA256:DHE-DSS-AES256-SHA:DHE-RSA-AES256-SHA:!aNULL:!eNULL:!EXPORT:!DES:!RC4:!MD5:!PSK:!aECDH:!EDH-DSS-DES-CBC3-SHA:!EDH-RSA-DES-CBC3-SHA:!KRB5-DES-CBC3-SHA';
ssl_dhparam /etc/nginx/ssl/dhparam.pem;
##
# Logging Settings
##
log_format main '$remote_addr - $remote_user [$time_local] "$ssl_protocol/$ssl_cipher" "$request" '
'"$status" $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"';
log_format nohost '$host $remote_addr [$time_local] "$request" '
'"$status" $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"';
access_log /var/log/nginx/access.log;
error_log /var/log/nginx/error.log;
##
# Gzip Settings
##
# gzip on;
# gzip_vary on;
# gzip_proxied any;
# gzip_comp_level 6;
# gzip_buffers 16 8k;
# gzip_http_version 1.1;
# gzip_types text/plain text/css application/json application/javascript text/xml application/xml application/xml+rss text/javascript;
##
# Virtual Host Configs
##
# include /etc/nginx/conf.d/*.conf;
# include /etc/nginx/sites-enabled/*;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-Proto $scheme;
map $scheme $hsts_header {
https "max-age=604800";
}
server { #不存在或恶意解析处理
listen 80 default_server;
listen [::]:80 default_server;
server_name _;
access_log /var/log/nginx/host.nohost.ustc.edu.cn.access.log nohost;
default_type 'text/html';
location / {
return 404 "<html><head><meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\"><title>404 Unknown Virtual Host</title><style>div{font-size:12px;}a{color:#1463da;text-decoration:none}a:hover{color:#1463da;text-decoration:underline;}</style></head><body bgcolor=\"white\"><center><h1>404 Unknown Virtual Host</h1></center><p><center>client: $remote_addr, request_host: $host, time: $date_local</center><hr><p><center><h1>您访问的域名不存在或已被关闭</h1></center><p><center>如有问题请联系系统管理员</center></body></html><!-- a padding to disable MSIE and Chrome friendly error page --><!-- a padding to disable MSIE and Chrome friendly error page --><!-- a padding to disable MSIE and Chrome friendly error page --><!-- a padding to disable MSIE and Chrome friendly error page --><!-- a padding to disable MSIE and Chrome friendly error page --><!-- a padding to disable MSIE and Chrome friendly error page -->";
}
location /nginx_status {
stub_status on;
access_log off;
allow 127.0.0.1;
deny all;
}
location /status {
root /usr/share/nginx/html/;
}
}
#配置模版1,重定向配置,访问这个主机直接重定向到一个页面
# server {
# listen 80 ;
# listen [::]:80 ;
# listen 443 ssl http2;
# listen [::]:443 ssl http2;
# server_name redir.ustc.edu.cn;
# ssl_certificate /etc/nginx/ssl/redir.ustc.edu.cn.pem;
# ssl_certificate_key /etc/nginx/ssl/redir.ustc.edu.cn.key;
# access_log /var/log/nginx/host.redir.ustc.edu.cn.access.log main;
# location / {
# rewrite ^ http://www.ustc.edu.cn/url/dir;
# }
# location /.well-known/ {
# root /etc/nginx/ssl/web/;
# }
# }
#
#配置模版2,http重定向到https(useragent 带有 Mozila/5.0),用于强制把http访问用户重定向到https
#
# server {
# listen 80;
# listen [::]:80;
# server_name www.ustc.edu.cn;
# access_log /var/log/nginx/host.www.ustc.edu.cn.access.log main;
# location / {
# if ( $http_user_agent ~ "(Mozilla/5.0)" ) {
# return 301 https://$server_name$request_uri;
# }
# proxy_pass http://202.38.64.99/;
# }
# location /.well-known/ {
# root /etc/nginx/ssl/web/;
# }
# }
# server {
# listen 443 ssl http2;
# listen [::]:443 ssl http2;
# server_name www.ustc.edu.cn;
# ssl_certificate /etc/nginx/ssl/www.ustc.edu.cn.pem;
# ssl_certificate_key /etc/nginx/ssl/www.ustc.edu.cn.key;
# access_log /var/log/nginx/host.www.ustc.edu.cn.access.log main;
# add_header Strict-Transport-Security $hsts_header;
# add_header Content-Security-Policy upgrade-insecure-requests;
# location / {
# proxy_pass http://202.38.64.99/;
# }
#}
#配置模版3,http对外服务网站
# server {
# listen 80 ;
# listen [::]:80 ;
# server_name www.ustc.edu.cn;
# access_log /var/log/nginx/host.www.ustc.edu.cn.access.log main;
# location / {
# proxy_pass http://202.38.64.99/;
# }
# }
#测试配置, 请修改下面的主机名、日志文件名和对应的IP地址
server {
listen 80 ;
listen [::]:80 ;
server_name www.ustc.edu.cn;
access_log /var/log/nginx/host.www.ustc.edu.cn.access.log main;
location / {
proxy_pass http://202.38.64.99/;
}
}
}