Nginx配置模板
作者Lou Xiao创建时间2020-04-19 22:44:00更新时间2020-04-21 21:12:00
主配置文件(/etc/nginx/nginx.conf)
1.双击鼠标左键复制此行;2.单击复制所有代码。
1
#/etc/nginx/nginx.conf
2
# For more information on configuration, see:
3
# * Official English Documentation: http://nginx.org/en/docs/
4
# * Official Russian Documentation: http://nginx.org/ru/docs/
5
6
user nginx;
7
worker_processes auto;
8
error_log /var/log/nginx/error.log;
9
pid /run/nginx.pid;
10
11
# Load dynamic modules. See /usr/share/nginx/README.dynamic.
12
include /usr/share/nginx/modules/*.conf;
13
14
events {
15
worker_connections 1024;
16
}
17
#load personal configure
18
19
stream {
20
include /home/User/nginx/*.conf;
21
include /root/nginx/*.conf;
22
}
23
24
http {
25
log_format main '[$time_iso8601] $remote_addr "$request" '
26
'$status $request_time $body_bytes_sent "$http_referer" '
27
'"$http_user_agent" "$http_x_forwarded_for"';
28
29
access_log /var/log/nginx/access.log main;
30
31
# gzip support
32
gzip on;
33
gzip_http_version 1.1;
34
gzip_comp_level 6;
35
gzip_min_length 1100;
36
gzip_buffers 4 8k;
37
gzip_types text/plain application/xhtml+xml text/css application/xml application/xml+rss text/javascript application/javascript application/x-javascript
38
gzip_proxied any;
39
gzip_disable "MSIE [1-6]\.";
40
41
sendfile on;
42
tcp_nopush on;
43
tcp_nodelay on;
44
keepalive_timeout 65;
45
types_hash_max_size 2048;
46
47
server_tokens off;
48
client_max_body_size 100M;
49
50
proxy_headers_hash_max_size 1024;
51
proxy_headers_hash_bucket_size 512;
52
server_names_hash_bucket_size 512;
53
54
include /etc/nginx/mime.types;
55
default_type application/octet-stream;
56
57
# Load modular configuration files from the /etc/nginx/conf.d directory.
58
# See http://nginx.org/en/docs/ngx_core_module.html#include
59
# for more information.
60
include /etc/nginx/conf.d/*.conf;
61
include /etc/nginx/vhosts/*.conf;
62
}
站点配置文件(/etc/nginx/vhosts/my.domain.com.conf)
1.双击鼠标左键复制此行;2.单击复制所有代码。
1
#/etc/nginx/vhosts/my.domain.com.conf
2
3
server {
4
listen 80;
5
server_name my.domain.com;
6
7
return 301 https://$host$request_uri;
8
9
access_log /var/log/nginx/my.domain.com.access.log main;
10
error_log /var/log/nginx/my.domain.com.error.log;
11
12
location / {
13
proxy_pass http://localhost:3031/;
14
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
15
proxy_set_header X-Forwarded-Proto $scheme;
16
proxy_set_header X-Forwarded-Port $server_port;
17
}
18
19
location /static/ {
20
alias /var/www/my.domain.com/static/;
21
autoindex off;
22
}
23
24
location /.well-known/ {
25
alias /var/www/my.domain.com/.well-known/;
26
autoindex off;
27
}
28
}
29
30
server {
31
listen 443 ssl;
32
server_name my.domain.com;
33
34
access_log /var/log/nginx/my.domain.com.access.log main;
35
error_log /var/log/nginx/my.domain.com.error.log;
36
37
ssl_certificate "/root/.getssl/my.domain.com/my.domain.com.chain.crt";
38
ssl_certificate_key "/root/.getssl/my.domain.com/my.domain.com.key";
39
40
ssl_session_cache shared:SSL:20m;
41
ssl_session_timeout 60m;
42
ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
43
ssl_prefer_server_ciphers on;
44
ssl_ciphers "ECDHE-ECDSA-CHACHA20-POLY1305:ECDHE-RSA-CHACHA20-POLY1305:ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES256-GCM-SHA384:ECDHE-RSA-AES256-GCM-SHA384:DHE-RSA-AES128-GCM-SHA256:DHE-RSA-AES256-GCM-SHA384:ECDHE-ECDSA-AES128-SHA256:ECDHE-RSA-AES128-SHA256:ECDHE-ECDSA-AES128-SHA:ECDHE-RSA-AES256-SHA384:ECDHE-RSA-AES128-SHA:ECDHE-ECDSA-AES256-SHA384:ECDHE-ECDSA-AES256-SHA:ECDHE-RSA-AES256-SHA:DHE-RSA-AES128-SHA256:DHE-RSA-AES128-SHA:DHE-RSA-AES256-SHA256:DHE-RSA-AES256-SHA:ECDHE-ECDSA-DES-CBC3-SHA:ECDHE-RSA-DES-CBC3-SHA:EDH-RSA-DES-CBC3-SHA:AES128-GCM-SHA256:AES256-GCM-SHA384:AES128-SHA256:AES256-SHA256:AES128-SHA:AES256-SHA:DES-CBC3-SHA:!DSS";
45
46
47
location / {
48
proxy_pass http://localhost:3031/;
49
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
50
proxy_set_header X-Forwarded-Proto $scheme;
51
proxy_set_header X-Forwarded-Port $server_port;
52
}
53
54
# proxy pass php
55
location ~ \.php$ {
56
fastcgi_pass 127.0.0.1:9000;
57
proxy_set_header X-Forwarded-For $remote_addr;
58
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
59
proxy_set_header Host $host;
60
fastcgi_index index.php;
61
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
62
include fastcgi_params;
63
}
64
65
location /static/ {
66
alias /var/www/my.domain.com/static/;
67
autoindex off;
68
}
69
70
location /.well-known/ {
71
alias /var/www/my.domain.com/.well-known/;
72
autoindex off;
73
}
74
75
location ~* \.html$ {
76
root /var/www/my.domain.com/;
77
autoindex off;
78
}
79
80
location /robots.txt {
81
root /var/www/my.domain.com/;
82
autoindex off;
83
}
84
}
文章目录