# Docker安装Nginx教程
mkdir -p /root/docker/nginx/{conf,html,logs}
chmod -R 777 /root/docker/nginx/conf
chmod -R 777 /root/docker/nginx/html
chmod -R 777 /root/docker/nginx/logs
docker run --name nginx-temp -d nginx
docker cp nginx-temp:/etc/nginx/nginx.conf /root/docker/nginx/conf
docker cp nginx-temp:/etc/nginx/conf.d /root/docker/nginx/conf
docker stop nginx-temp && docker rm nginx-temp
docker run -d --name nginx -p 80:80 -p 443:443 -v /root/docker/nginx/html:/usr/share/nginx/html -v /root/docker/nginx/conf/nginx.conf:/etc/nginx/nginx.conf -v /root/docker/nginx/conf/conf.d:/etc/nginx/conf.d -v /root/docker/nginx/logs:/var/log/nginx nginx:1.18.0
docker run -d --name nginx -p 80:80 -p 443:443 -v /root/docker/nginx/html:/usr/share/nginx/html -v /root/docker/nginx/conf/nginx.conf:/etc/nginx/nginx.conf -v /root/docker/nginx/conf/conf.d:/etc/nginx/conf.d -v /root/ssl/nginx:/etc/nginx/ssl:ro -v /root/docker/nginx/logs:/var/log/nginx nginx:1.18.0
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
Centos7安装本地docker
sudo yum install -y nginx
如果想设置系统启动的时候启动Nginx使用
sudo systemctl start nginx
sudo systemctl enable nginx
# 永久开放 HTTP 和 HTTPS 端口
sudo firewall-cmd --permanent --add-service=http
sudo firewall-cmd --permanent --add-service=https
# 重载防火墙以使更改生效
sudo firewall-cmd --reload
# 验证开放的端口和服务
sudo firewall-cmd --list-all
#查看Nginx状态
sudo systemctl status nginx
#检查Nginx语法
sudo nginx -t
# 启动 Nginx
sudo systemctl start nginx
# 停止 Nginx
sudo systemctl stop nginx
# 重启 Nginx (完全重启)
sudo systemctl restart nginx
# 重载 Nginx (不中断服务的情况下重新加载配置)
sudo systemctl reload nginx
# 检查 Nginx 状态
sudo systemctl status nginx
# 启用开机自启
sudo systemctl enable nginx
# 禁用开机自启
sudo systemctl disable nginx
# 测试配置文件语法
sudo nginx -t
#查看可用的版本号
yum --showduplicates list nginx
# 例如,安装 1.24.0 版本
sudo yum install -y nginx-1:1.24.0-1.el7.ngx
# 或者安装 1.22.0 版本
sudo yum install -y nginx-1:1.22.0-1.el7.ngx
#如果没有添加Nginx仓库需要添加仓库
sudo vi /etc/yum.repos.d/nginx.repo
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
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
把以下内容存到文件中
[nginx-stable]
name=nginx stable repo
baseurl=http://nginx.org/packages/centos/$releasever/$basearch/
gpgcheck=1
enabled=1
gpgkey=https://nginx.org/keys/nginx_signing.key
module_hotfixes=true
[nginx-mainline]
name=nginx mainline repo
baseurl=http://nginx.org/packages/mainline/centos/$releasever/$basearch/
gpgcheck=1
enabled=0
gpgkey=https://nginx.org/keys/nginx_signing.key
module_hotfixes=true
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
2
3
4
5
6
7
8
9
10
11
12
13
14
15