【Nginx】Docker中部署反向代理
本文介绍了如何在服务器 Centos7 上使用 Docker 搭建 Nginx 实现反向代理。
安装 Docker
配置 Docker 数据保存路径
设置 Docker 代理
预先拉取镜像
1
docker pull nginx
创建配置文件
1
2
3mkdir -p /root/nginx_proxy
cd /root/nginx_proxy
vim 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
72user nginx;
worker_processes auto;
error_log /var/log/nginx/error.log notice;
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 65;
#gzip on;
server {
listen 80;
listen [::]:80;
server_name localhost;
#access_log /var/log/nginx/host.access.log main;
location / {
root /usr/share/nginx/html;
index index.html index.htm;
}
#error_page 404 /404.html;
# redirect server error pages to the static page /50x.html
#
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /usr/share/nginx/html;
}
# proxy the PHP scripts to Apache listening on 127.0.0.1:80
#
#location ~ \.php$ {
# proxy_pass http://127.0.0.1;
#}
# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
#
#location ~ \.php$ {
# root html;
# fastcgi_pass 127.0.0.1:9000;
# fastcgi_index index.php;
# fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name;
# include fastcgi_params;
#}
# deny access to .htaccess files, if Apache's document root
# concurs with nginx's one
#
#location ~ /\.ht {
# deny all;
#}
}
}部署 Nginx
1
2
3
4
5
6
7
8
9
10
11docker run -d \
--name nginx_proxy \
--restart always \
--link nextcloud \
--link gitlab \
-p 80:80 \
-p 443:443 \
-v /root/nginx_proxy/nginx.conf:/etc/nginx/nginx.conf \
-v /root/nginx_proxy/ssl:/root/ssl/ \
-v /home/git/www:/usr/share/nginx/html/ \
nginx
【Nginx】Docker中部署反向代理