docker安装nginx以及(nginxWebUI和nginx-gui图形化界面的使用)

10 篇文章 0 订阅

一、docker安装nginx

1、拉取镜像

docker pull nginx

2、创建挂载目录

mkdir -vp /usr/local/docker/nginx
cd /usr/local/docker/nginx
#创建用户挂在的目录
mkdir -vp logs html conf/conf.d

3、启动镜像

1、方式一(推荐)

1、启动
docker run -d --name nginx -p 80:80 nginx
2、拷贝容器里面的nginx配置文件

nginx:此名称是容器的唯一id(可以是名字,确保唯一即可,因为我上面启动适用的名称是nginx)

#将容器nginx.conf文件复制到宿主机
docker cp nginx:/etc/nginx/nginx.conf /usr/local/docker/nginx/
#将容器conf.d文件夹下内容复制到宿主机
docker cp nginx:/etc/nginx/conf.d /usr/local/docker/nginx/conf
#将容器中的html文件夹复制到宿主机
docker cp nginx:/usr/share/nginx/html/ /usr/local/docker/nginx/
#将容器中的log下的文件复制到宿主机
docker cp nginx:/var/log/nginx/ /usr/local/docker/nginx/logs/
3、停止容器并删除
#1、停止之前的nginx
docker stop nginx
#2、删除启动的容器
docker rm -f nginx
4、启动容器

2、方式二

1、准备nginx.conf文件

vim /usr/local/docker/nginx/nginx.conf

user  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;
    include /etc/nginx/conf.d/*.conf;
}
2、准备default.conf文件

cd /usr/local/docker/nginx/conf/conf.d
vim default.conf

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;
        #}
}
3、准备50x.html

vim /usr/local/docker/nginx/html/50x.html

<html>
	<head>
		<title>Error</title>
		<style>
			html { color-scheme: light dark; }
			body { width: 35em; margin: 0 auto;
			font-family: Tahoma, Verdana, Arial, sans-serif; }
		</style>
	</head>
	<body>
		<h1>An error occurred.</h1>
		<p>Sorry, the page you are looking for is currently unavailable.
			<br />
			Please try again later.</p>
		<p>If you are the system administrator of this resource then you should check
			the error log for details.</p>
		<p>
			<em>Faithfully yours, nginx.</em>
		</p>
	</body>
</html>
4、准备index.html

vim /usr/local/docker/nginx/html/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> 
5、启动容器

4、重新启动nginx

docker run  --name nginx -m 200m -p 80:80 \
-v /usr/local/docker/nginx/nginx.conf:/etc/nginx/nginx.conf \
-v /usr/local/docker/nginx/logs:/var/log/nginx \
-v /usr/local/docker/nginx/html:/usr/share/nginx/html \
-v /usr/local/docker/nginx/conf/conf.d:/etc/nginx/conf.d \
-e TZ=Asia/Shanghai \
--privileged=true -d nginx

5、注意

1、在宿主机/usr/local/docker/nginx/html上修改html目录下的文件是即时生效的。

2、修改宿主机的nginx.conf和conf/conf.d目录下的配置文件后,需要重启容器重新加载配置。

3、配置路径,要使用容器中的路径。因为在启动容器的-v环境中指定了容器数据卷

6、访问地址

  • 开启80端口

firewall-cmd --zone=public --add-port=80/tcp --permanent && firewall-cmd --reload

http://192.168.11.142:80

二、图形化界面-nginxGUI

官网

https://github.com/onlyGuo/nginx-gui

centos7的安装

1、下载

下载对应的版本

mkdir -vp /usr/local/software/nginx-gui
cd /usr/local/software/nginx-gui
wget https://github.com/onlyGuo/nginx-gui/releases/download/1.6/Nginx-GUI-For-Linux_X64_v1.6.zip

2、配置

1、解压缩

#解压
unzip  Nginx-GUI-For-Linux_X64_v1.6.zip
#修改文件名称
mv Nginx-GUI-For-Linux_X64_v1.6 nginx-gui
#进入工作目录
cd nginx-gui
#修改配置文件
vim conf/conf.properties

2、修改nginx的目录环境以及登录用户名密码

cd /usr/local/software/nginx-gui/nginx-gui/conf
vim conf.properties
#配置nginx的路径
nginx.path = /usr/local/docker/nginx/
nginx.config = /usr/local/docker/nginx/conf/nginx.conf
#配置登录gui系统管理界面的用户名密码
account.admin = admin
#account.password= admin123456

3、配置端口

cd /usr/local/software/nginx-gui/nginx-gui/bin
vim application.yml

启动nginx-gui

chmod 777  /usr/local/software/nginx-gui/*
cd /usr/local/software/nginx-gui/nginx-gui
sh startup.sh
#开放端口
firewall-cmd --zone=public --add-port=8889/tcp --permanent && firewall-cmd --reload

二、图形化界面-nginxWebUI

1、拉取

#创建挂载的目录文件
mkdir -vp /usr/local/docker/nginxWebUI
docker pull cym1102/nginxwebui:latest

2、启动

docker run -itd \
  -v /usr/local/docker/nginxWebUI:/home/nginxWebUI \
  -e BOOT_OPTIONS="--server.port=8089" \
  --privileged=true \
  --net=host \
  --name=nginxWebUI  cym1102/nginxwebui:latest

3、访问信息

http://192.168.11.142:8089

  • 第一次打开需要初始化密码:本人设置的admin/adminA12345
    在这里插入图片描述
    在这里插入图片描述
    在这里插入图片描述
  • 1
    点赞
  • 15
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
使用Docker安装Nginx并配置SSL证书的步骤如下: 1. 准备SSL证书:根据不同的云服务商,证书文件的后缀可能有所不同。腾讯云的证书文件后缀为.crt和.key,阿里云的证书文件后缀为.pem和.key。确保证书文件正确并可用。 2. 下载最新的Nginx镜像:使用以下命令下载最新的Nginx镜像: ``` docker pull nginx ``` 3. 创建目录:创建几个目录,用于挂载Nginx容器内的配置文件和日志文件。使用以下命令创建目录: ``` mkdir -p /usr/local/nginx/{conf,html,logs,ssl} ``` 4. 启动一个Nginx临时容器:使用以下命令启动一个Nginx临时容器,并将配置文件复制到主机上: ``` docker run --name nginx-temp -d nginx docker cp nginx-temp:/etc/nginx/nginx.conf /usr/local/nginx/conf/nginx.conf docker rm -f nginx-temp ``` 5. 上传SSL证书:将SSL证书上传到服务器的指定目录,例如将证书文件复制到/usr/local/nginx/ssl目录下。 6. 修改nginx.conf配置文件:编辑/usr/local/nginx/conf/nginx.conf文件,配置SSL证书的路径。确保路径是在容器内的地址,而不是主机的地址。 7. 正式启动Nginx使用以下命令启动Nginx容器,并将挂载目录和端口映射配置好: ``` docker run --name nginx -p 80:80 -p 443:443 \ -v /usr/local/nginx/html:/usr/share/nginx/html \ -v /usr/local/nginx/conf/nginx.conf:/etc/nginx/nginx.conf \ -v /usr/local/nginx/conf.d:/etc/nginx/conf.d \ -v /usr/local/nginx/logs:/var/log/nginx \ -v /usr/local/nginx/ssl:/etc/nginx/ssl \ --privileged=true -d --restart=always nginx ``` 8. 检查Nginx是否成功启动:使用以下命令检查Nginx容器是否成功启动: ``` docker ps ``` 以上是使用Docker安装Nginx并配置SSL证书的步骤。请根据实际情况进行操作。\[1\]\[2\]\[3\] #### 引用[.reference_title] - *1* *2* *3* [docker安装nginx并配置ssl证书](https://blog.csdn.net/LuoHuaX/article/details/127320361)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^control_2,239^v3^insert_chatgpt"}} ] [.reference_item] [ .reference_list ]

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值