Docker安装Nginx

Docker安装Nginx

数据卷规划

安装命令

1
docker run -d -p 80:80 --name fhltestnginx -v ~/Documents/software/docker_volume_mapping/nginx/www:/opt/www -v ~/Documents/software/docker_volume_mapping/nginx/conf/nginx.conf:/etc/nginx/nginx.conf -v ~/Documents/software/docker_volume_mapping/nginx/conf/conf.d:/etc/nginx/conf.d -v ~/Documents/software/docker_volume_mapping/nginx/logs:/var/log/nginx  nginx:latest

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
user  root;
worker_processes 1;
error_log /var/log/nginx/error.log warn;
pid /var/run/nginx.pid;
events {
worker_connections 1024;
}
http {
include /etc/nginx/mime.types;
default_type application/octet-stream;
log_format main '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"';
access_log /var/log/nginx/access.log main;
sendfile on;
#tcp_nopush on;
keepalive_timeout 120;
client_max_body_size 20m;
#gzip on;


server {
listen 80;
server_name xxxx.yyyy.zzzz;
#root /usr/share/nginx/html;
#root /opt/www/redis_geektime/html;
index index.php index.html index.htm;

location / {
root /opt/www/;
}

# if (!-e $request_filename) {
# root /opt/www/SpringSeries;
# }


location /redis {
alias /opt/www/redis_geektime/html;
#指定主页
index index.html;
#自动跳转
autoindex on;
}

location /interview {
alias /opt/www/interview/;
#指定主页
index index.html;
#自动跳转
autoindex on;
}

location /Spring {
alias /opt/www/Spring;
#指定主页
index index.html;
#自动跳转
autoindex on;
}

location /Netty {
alias /opt/www/Netty;
#指定主页
index index.html;
#自动跳转
autoindex on;
}

location /StudyGuide {
alias /opt/www/StudyGuide;
#指定主页
index index.html;
#自动跳转
autoindex on;
}

location /Dubbo {
alias /opt/www/Dubbo;
#指定主页
index index.html;
#自动跳转
autoindex on;
}

location /SpringMVC {
alias /opt/www/SpringMVC;
#指定主页
index index.html;
#自动跳转
autoindex on;
}


location /SpringBoot {
alias /opt/www/SpringBoot;
#指定主页
index index.html;
#自动跳转
autoindex on;
}

location /mybatis {
alias /opt/www/mybatis;
#指定主页
index index.html;
#自动跳转
autoindex on;
}

location /JDK {
alias /opt/www/JDK;
#指定主页
index index.html;
#自动跳转
autoindex on;
}

location /RedisSource {
alias /opt/www/RedisSource;
#指定主页
index index.html;
#自动跳转
autoindex on;
}

location /DatabaseDesign {
alias /opt/www/DatabaseDesign;
#指定主页
index index.html;
#自动跳转
autoindex on;
}

location /SpringSeries{
alias /opt/www/SpringSeries;
#指定主页
index index.html;
#自动跳转
autoindex on;
}

# 该配置能成功访问到静态pdf资源
location /pdfjs {
alias /opt/www/static/pdfjs;
}


# location /pdfjs {
# alias /opt/www/SpringSeries;
# }


location ~* \.(gif|jpg|jpeg|bmp|png|ico|txt|js|css)$ {
root /opt/www/static;
expires 30d;
}

}
}


Docker安装Nginx
http://dantefung.github.io/2022/07/17/Docker安装Nginx/
Beitragsautor
DANTE FUNG
Veröffentlicht am
July 17, 2022
Urheberrechtshinweis