IT数码 购物 网址 头条 软件 日历 阅读 图书馆
TxT小说阅读器
↓语音阅读,小说下载,古典文学↓
图片批量下载器
↓批量下载图片,美女图库↓
图片自动播放器
↓图片自动播放器↓
一键清除垃圾
↓轻轻一点,清除系统垃圾↓
开发: C++知识库 Java知识库 JavaScript Python PHP知识库 人工智能 区块链 大数据 移动开发 嵌入式 开发工具 数据结构与算法 开发测试 游戏开发 网络协议 系统运维
教程: HTML教程 CSS教程 JavaScript教程 Go语言教程 JQuery教程 VUE教程 VUE3教程 Bootstrap教程 SQL数据库教程 C语言教程 C++教程 Java教程 Python教程 Python3教程 C#教程
数码: 电脑 笔记本 显卡 显示器 固态硬盘 硬盘 耳机 手机 iphone vivo oppo 小米 华为 单反 装机 图拉丁
 
   -> 系统运维 -> 【三分钟教程】docker快速部署nginx服务 -> 正文阅读

[系统运维]【三分钟教程】docker快速部署nginx服务

1、下载nginx镜像

[root@localhost /]# docker pull nginx:1.14
1.14: Pulling from library/nginx
27833a3ba0a5: Pull complete 
0f23e58bd0b7: Pull complete 
8ca774778e85: Pull complete 
Digest: sha256:f7988fb6c02e0ce69257d9bd9cf37ae20a60f1df7563c3a2a6abe24160306b8d
Status: Downloaded newer image for nginx:1.14

2、新建nginx挂载目录:

[root@localhost /]# mkdir -p /mnt/public/nginx/{conf,html,logs,cert}
[root@localhost /]# tree /mnt/public/
/mnt/public/
└── nginx
    ├── cert
    ├── conf
    ├── html
    └── logs

5 directories, 0 files

3、编写nginx容器启动脚本

[root@localhost nginx]# pwd
/mnt/public/nginx

[root@localhost nginx]# vim run.sh 

#!/bin/bash

docker run -itd --restart=unless-stopped \
 -v /etc/localtime:/etc/localtime \
 -v /etc/timezone:/etc/timezone \
 --network=host \
 --name nginx \
 -v /mnt/public/nginx/html:/usr/share/nginx/html \
 -v /mnt/public/nginx/logs:/var/log/nginx \
 -v /mnt/public/nginx/cert:/etc/nginx/cert \
 -v /mnt/public/nginx/nginx.conf:/etc/nginx/nginx.conf \
 -v /mnt/public/nginx/conf:/etc/nginx/conf.d \
 nginx:1.14 

docker logs -f nginx

4、为脚本赋予执行权限

[root@localhost nginx]# chmod +x run.sh 
[root@localhost nginx]# ll run.sh 
-rwxr-xr-x 1 root root 434 7月  23 10:44 run.sh

5、编写nginx主配置文件

[root@localhost nginx]# pwd
/mnt/public/nginx


[root@localhost nginx]# vim nginx.conf 

worker_processes  4;
user  nginx;
#pid /opt/app/nginx/sbin/nginx.pid;
events {
    worker_connections  409600;
}
http {
    include       mime.types;
    default_type  application/octet-stream;
    server_tokens  off;
    autoindex on;
    autoindex_exact_size off;
    autoindex_localtime on;
    keepalive_timeout  65;
    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;
    error_log  /var/log/nginx/error.log  error;
    include /etc/nginx/conf.d/*.conf;
}

6、编写nginx虚拟主机配置文件

[root@localhost conf]# pwd
/mnt/public/nginx/conf
[root@localhost conf]# ls
nginx-443.conf.template  nginx-php.conf.template  nginx.template.conf

  • https域名conf文件配置
[root@localhost conf]# vim nginx-443.conf

server {
        listen       80;
        server_name 127.0.0.1;
        rewrite ^ https://$http_host$request_uri? permanent;
        server_tokens off;
    }
server {
        listen 443 ssl;
        server_name  127.0.0.1;
        ssl_certificate   /etc/nginx/cert/xxx.com.pem;
        ssl_certificate_key  /etc/nginx/cert/xxx.com.key;
        ssl_session_timeout 5m;
        ssl_ciphers ECDHE-RSA-AES128-GCM-SHA256:ECDHE:ECDH:AES:HIGH:!NULL:!aNULL:!MD5:!ADH:!RC4;
        ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
        ssl_prefer_server_ciphers on;
        charset utf-8;
        location / {
            root /usr/share/nginx/html;
            index  index.php index.html index.htm;
        }
}
  • http域名conf文件配置
[root@localhost conf]# vim nginx.template.conf 

server {
        listen 80;
        server_name  127.0.0.1;
        charset utf-8;
        location / {
            root /usr/share/nginx/html;
            index  index.php index.html index.htm;
        }
}
  • 反向代理配置
server {
	listen 80;
	server_name  127.0.0.1;
	
	location /  {
		proxy_redirect  off;
		proxy_pass http://0.0.0.0/;
	}
      access_log /var/log/nginx/access.log main;
}
  • php环境conf文件配置
[root@k8s-node2 conf]# vim nginx-php.conf.template 

server {
        listen       80;
        server_name  127.0.0.1;
        location / {
            root /usr/share/nginx/html;
            index  index.php index.html index.htm;
        }
        location ~* .*\.(php|php5)?$ {
             root    html;
             fastcgi_pass  127.0.0.1:9000;
             fastcgi_index index.php;
             include fastcgi.conf;
        }
        access_log  /var/log/nginx/access.xxx.com.log  main;

}
  系统运维 最新文章
配置小型公司网络WLAN基本业务(AC通过三层
如何在交付运维过程中建立风险底线意识,提
快速传输大文件,怎么通过网络传大文件给对
从游戏服务端角度分析移动同步(状态同步)
MySQL使用MyCat实现分库分表
如何用DWDM射频光纤技术实现200公里外的站点
国内顺畅下载k8s.gcr.io的镜像
自动化测试appium
ctfshow ssrf
Linux操作系统学习之实用指令(Centos7/8均
上一篇文章      下一篇文章      查看所有文章
加:2021-08-14 14:33:10  更:2021-08-14 14:35:30 
 
开发: C++知识库 Java知识库 JavaScript Python PHP知识库 人工智能 区块链 大数据 移动开发 嵌入式 开发工具 数据结构与算法 开发测试 游戏开发 网络协议 系统运维
教程: HTML教程 CSS教程 JavaScript教程 Go语言教程 JQuery教程 VUE教程 VUE3教程 Bootstrap教程 SQL数据库教程 C语言教程 C++教程 Java教程 Python教程 Python3教程 C#教程
数码: 电脑 笔记本 显卡 显示器 固态硬盘 硬盘 耳机 手机 iphone vivo oppo 小米 华为 单反 装机 图拉丁

360图书馆 购物 三丰科技 阅读网 日历 万年历 2024年5日历 -2024/5/21 0:18:36-

图片自动播放器
↓图片自动播放器↓
TxT小说阅读器
↓语音阅读,小说下载,古典文学↓
一键清除垃圾
↓轻轻一点,清除系统垃圾↓
图片批量下载器
↓批量下载图片,美女图库↓
  网站联系: qq:121756557 email:121756557@qq.com  IT数码