forked from codeskyblue/gohttpserver
-
Notifications
You must be signed in to change notification settings - Fork 0
/
nginx_example_withssl.conf
100 lines (89 loc) · 3.74 KB
/
nginx_example_withssl.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
#Use Nginx with ssl to deploy GoHttpFileServer Example(https://github.com/codeskyblue/gohttpserver)
#Nginx搭配SSL反向代理至GoHttpFileServer的例子
#By h45251880,Tested on windows 10
worker_processes auto;
events {
multi_accept on;
worker_connections 65535;
}
http {
include mime.types;
default_type application/octet-stream;
#优化
#optimization
sendfile on;
tcp_nopush on;
server_tokens off;
tcp_nodelay on;
#开启Gzip
#enable Gzip
gzip on;
gzip_vary on;
gzip_proxied any;
gzip_comp_level 6;
gzip_types text/plain text/css text/xml application/json application/javascript application/rss+xml application/atom+xml image/svg+xml;
server {
#强制Https #Mandatory Https
listen 80 default_server;
listen [::]:80 default_server;
server_name your_domain; #网域 #domain
location / {
return 301 https://$host$request_uri;
}
}
server {
listen 443 ssl http2;
listen [::]:443 ssl http2;
server_name your_domain;
#禁止真实ip访问
#ban real ip access
#if ($host != 'your_domain') {
# rewrite ^/(.*)$ https://your_domain/$1 permanent;
#}
#防爬虫、压力、节点测试等等...
#No spider、webbench、ping...
#if ($http_user_agent ~* (Scrapy|Curl|HttpClient)) {
# return 403;
#}
#if ($http_user_agent ~ "FeedDemon|JikeSpider|Indy Library|Alexa Toolbar|AskTbFXTV|AhrefsBot|CrawlDaddy|CoolpadWebkit|Java|Feedly|UniversalFeedParser|ApacheBench|Microsoft URL Control|Swiftbot|ZmEu|oBot|jaunty|Python-urllib|lightDeckReports Bot|YYSpider|DigExt|YisouSpider|HttpClient|MJ12bot|heritrix|EasouSpider|LinkpadBot|Ezooms|^$" ) {
# return 403;
#}
#if ($request_method !~ ^(GET|HEAD|POST)$) {
# return 403;
#}
#if ($http_user_agent ~* (Wget|ab) ) {
# return 403;
#}
#if ($http_user_agent ~* LWP::Simple|BBBike|wget) {
# return 403;
#}
#SSL设置(Let's Encrypt)
#SSL Settings(Let's Encrypt)
#Reference from https://ssl-config.mozilla.org/
ssl_certificate fullchain1.pem;
ssl_certificate_key privkey1.pem;
ssl_trusted_certificate chain1.pem;
ssl_session_timeout 1d;
ssl_session_cache shared:SSL:10m;
ssl_session_tickets off;
ssl_dhparam ffdhe2048.txt; #https://ssl-config.mozilla.org/ffdhe2048.txt
ssl_protocols TLSv1.2 TLSv1.3;
ssl_ciphers ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES256-GCM-SHA384:ECDHE-RSA-AES256-GCM-SHA384:ECDHE-ECDSA-CHACHA20-POLY1305:ECDHE-RSA-CHACHA20-POLY1305:DHE-RSA-AES128-GCM-SHA256:DHE-RSA-AES256-GCM-SHA384;
ssl_prefer_server_ciphers off;
add_header Strict-Transport-Security "max-age=63072000" always;
ssl_stapling on;
ssl_stapling_verify on;
resolver 1.1.1.1 1.0.0.1 [2606:4700:4700::1111] [2606:4700:4700::1001] 8.8.8.8 8.8.4.4 [2001:4860:4860::8888] [2001:4860:4860::8844] 208.67.222.222 208.67.220.220 [2620:119:35::35] [2620:119:53::53] 9.9.9.9 149.112.112.112 [2620:fe::fe] [2620:fe::9] 64.6.64.6 64.6.65.6 [2620:74:1b::1:1] [2620:74:1c::2:2] valid=60s;
#设置到GoHttpFileServer
#set to GoHttpFileServer
location / {
proxy_pass http://127.0.0.1:8000; #GoHttpFileServer的端口 #GoHttpFileServer port
proxy_redirect off;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
client_max_body_size 0; #disable upload limit
}
}
}