推荐文章:
【合集】Docker
Nginx配置Https免费证书
docker-run命令启动
第一次运行容器,目的:复制nginx里面的配置目录和html目录到宿主机
1
2
3
4
5
6
7
8
9
10
11
12
|
docker rm -f nginx
docker run --name nginx \
-p 80:80 \
-p 443:443 \
-v ~/nginx/logs:/var/log/nginx \
--restart always \
-d nginx
# 复制nginx目录到config
docker container cp nginx:/etc/nginx ~/nginx/config
# 复制html目录到html
docker container cp nginx:/usr/share/nginx/html ~/nginx/html
|
删除后重启,并挂载配置容器卷
1
2
3
4
5
6
7
8
9
|
docker rm -f nginx
docker run --name nginx \
-p 80:80 \
-p 443:443 \
-v ~/nginx/html:/usr/share/nginx/html \
-v ~/nginx/logs:/var/log/nginx \
-v ~/nginx/config:/etc/nginx \
--restart always \
-d nginx
|
60.44.3.223 访问nginx(记得服务器安全组80端口打开)
上传网站文件,配置 nginx.conf
将要部署的网站文件夹,放到html文件夹下面
将下面server覆写到default.conf
1
2
3
4
5
6
7
8
9
10
11
12
|
server {
listen 80;
# 注意:root对应的是nginx容器内部的目录,而不是数据卷的路径
root /usr/share/nginx/html/zxalive/public;
index index.html index.htm index.php;
server_name localhost;
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /usr/share/nginx/html/zxalive/public;
}
}
|
docker restart nginx
重启nginx容器后,再次ip访问234.44.3.223
,成功
其他项目的default.conf
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
|
server
{
listen 80;
server_name 116.62.6.243;
index index.html index.htm index.php;
root /usr/share/nginx/html/dist-pc;
location / {
if ( $http_user_agent ~ "(MIDP)|(WAP)|(UP.Browser)|(Smartphone)|(Obigo)|(Mobile)|(AU.Browser)|(wxd.Mms)|(WxdB.Browser)|(CLDC)|(UP.Link)|(KM.Browser)|(UCWEB)|(SEMC\-Browser)|(Mini)|(Symbian)|(Palm)|(Nokia)|(Panasonic)|(MOT\-)|(SonyEricsson)|(NEC\-)|(Alcatel)|(Ericsson)|(BENQ)|(BenQ)|(Amoisonic)|(Amoi\-)|(Capitel)|(PHILIPS)|(SAMSUNG)|(Lenovo)|(Mitsu)|(Motorola)|(SHARP)|(WAPPER)|(LG\-)|(LG/)|(EG900)|(CECT)|(Compal)|(kejian)|(Bird)|(BIRD)|(G900/V1.0)|(Arima)|(CTL)|(TDG)|(Daxian)|(DAXIAN)|(DBTEL)|(Eastcom)|(EASTCOM)|(PANTECH)|(Dopod)|(Haier)|(HAIER)|(KONKA)|(KEJIAN)|(LENOVO)|(Soutec)|(SOUTEC)|(SAGEM)|(SEC\-)|(SED\-)|(EMOL\-)|(INNO55)|(ZTE)|(iPhone)|(Android)|(Windows CE)|(Wget)|(Java)|(curl)|(Opera)" ) {
root /usr/share/nginx/html/dist;
}
}
location /admin {
alias /usr/share/nginx/html/dist-admin;
}
}
|