0%

Nginx代理多个域名服务配置参考[Django][Nginx][Uwsgi][资源服务器]

原文链接:Nginx代理多个域名服务配置参考[Django][Nginx][Uwsgi][资源服务器]

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
user www-data;
worker_processes auto;
pid /run/nginx.pid;
include /etc/nginx/modules-enabled/*.conf;

events {
worker_connections 768;
# 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 64;
# server_name_in_redirect off;

include /etc/nginx/mime.types;
default_type application/octet-stream;

##
# SSL Settings
##

ssl_protocols TLSv1 TLSv1.1 TLSv1.2 TLSv1.3; # Dropping SSLv3, ref: POODLE
ssl_prefer_server_ciphers on;

##
# Logging Settings
##

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/*;
}

nginx配置网站

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
upstream django {
#server unix:///web/djangoweb/uwsgi.sock; # uwsgi套接字通信
server 127.0.0.1:8001; #接口通信
}

server {
listen 80;
server_name www.aidroid.top aidroid.top ;
charset utf-8;
client_max_body_size 75M;


location /media {
alias /web/djangoweb/media;
}
location /static {
alias /web/djangoweb/static;
}
#location / {
# uwsgi_pass django2;
#
#}

location / {
uwsgi_pass django;
#proxy_set_header x-real-ip $remote_addr;
#proxy_set_header host $http_host;
#proxy_pass http://0.0.0.0:8001;
include /etc/nginx/uwsgi_params;
}
}

nginx实现静态资源服务器配置

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
autoindex on;             #开启索引功能
autoindex_exact_size off; # 关闭计算文件确切大小(单位bytes),只显示大概大小(单位kb、mb、gb)
autoindex_localtime on; # 显示本机时间而非 GMT 时间
charset utf-8; # 避免中文乱码

server {
listen 80; #监听端口号
server_name resource.aidroid.top;
#root /usr/share/nginx/html;
root /web/resource; # 共享的文件目录
error_log /web/logs/res_error.log ; # 报错的文件目录

location / {
}

error_page 404 /404.html;
location = /40x.html {
}

error_page 500 502 503 504 /50x.html;
location = /50x.html {
}
}

nginx 配置端口服务,同时启动blog/main/email/resource多个代理

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17

server {
listen 80;
server_name blog.aidroid.top ;
charset utf-8;
client_max_body_size 75M;

location / {
proxy_pass http://127.0.0.1:8002; # 转发规则
proxy_set_header Host $proxy_host; # 修改转发请求头,让8002端口的应用可以受到真实的请求
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}

}