Nginx 环境配置

一:基础安装

docker run \
--restart always \
--name Nginx \
-d \
-p 80:80 \
nginx

在这里插入图片描述
restart 重启策略,always 是一直保持重启。如果不设置,可以把这条删掉。never\always
8090 - 容器端口、80 - 服务器端口,这样外部通过80端口即可访问。
二:管理配置
首次部署 nginx 后,其实我们还不好操作配置文件。也就是 Nginx 的配置文件是在 Docker 容器的程序下,只有把它拷贝到服务器上才好操作。
进入 Nginx
进入程序:docker exec -it Nginx /bin/bash - 退出程序:exit

[root@vultr ~]# docker exec -it Nginx /bin/bash
root@ed8dc07f2ae6:/# ls
bin  boot  dev  docker-entrypoint.d  docker-entrypoint.sh  etc  home  lib  lib64  media  mnt  opt  proc  root  run  sbin  srv  sys  tmp  usr  var
root@ed8dc07f2ae6:/# cd etc/nginx/
root@ed8dc07f2ae6:/etc/nginx# ls
conf.d  fastcgi_params  mime.types  modules  nginx.conf  scgi_params  uwsgi_params
root@ed8dc07f2ae6:/etc/nginx# pwd
/etc/nginx
root@ed8dc07f2ae6:/# cd /usr/share/nginx/html
root@ed8dc07f2ae6:/usr/share/nginx/html# ls
50x.html  index.html
root@ed8dc07f2ae6:/usr/share/nginx/html# cat index.html 


<!DOCTYPE html>
<html>
<head>
<title>Welcome to nginx!</title>
<style>
html {
    color-scheme: light dark; }
body {
    width: 35em; margin: 0 auto;
font-family: Tahoma, Verdana, Arial, sans-serif; }
</style>
</head>
<body>
<h1>Welcome to nginx!</h1>
<p>If you see this page, the nginx web server is successfully installed and
working. Further configuration is required.</p>

<p>For online documentation and support please refer to
<a href="http://nginx.org/">nginx.org</a>.<br/>
Commercial support is available at
<a href="http://nginx.com/">nginx.com</a>.</p>

<p><em>Thank you for using nginx.</em></p>
</body>
</html>


root@ed8dc07f2ae6:/usr/share/nginx/html# 
root@ed8dc07f2ae6:/usr/share/nginx/html# exit
exit

配置:/etc/nginx
网页:/usr/share/nginx/html
拷贝 Nginx
创建目录

[root@vultr ~]# mkdir -p /data/nginx/conf
[root@vultr ~]# mkdir -p /data/nginx/html

拷贝文件

[root@vultr ~]# docker container cp Nginx:/etc/nginx/nginx.conf /data/nginx/conf
[root@vultr ~]# docker container cp Nginx:/usr/share/nginx/html/index.html /data/nginx/html

查看信息

[root@vultr ~]# ls /data/nginx/conf/
nginx.conf
[root@vultr ~]# ls /data/nginx/html/
index.html

部署 Nginx

docker run \
--restart always \
--name Nginx \
-d \
-v /data/nginx/html:/usr/share/nginx/html \
-v /data/nginx/conf/nginx.conf:/etc/nginx/nginx.conf \
-p 80:80 \
nginx

重启:sudo service nginx restart
证书安装
创建证书
SSL 免费的证书,一种是 ssl - 支持自动续期 (opens new window)另外各个云服务厂商都有提供,可以自己申请。这里以阿里云/京东云举例;
在这里插入图片描述
步骤1;通过免费的方式创建 SSL,之后通过引导的 DNS 方式进行验证。其实就是在你的域名里配置下验证信息。
步骤2;申请后,3-5分钟左右 DNS 会验证通过,这个时候你直接下载 Nginx 的

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值