部署nginx
nginx #打開 nginx
nginx -t #測試配置文件是否有語法錯誤
nginx -s reopen #重啟Nginx
nginx -s reload #重新加載Nginx配置文件,然后以優雅的方式重啟Nginx
nginx -s stop #強制停止Nginx服務
nginx -s quit #優雅地停止Nginx服務(即處理完所有請求后再停止服務)
nginx [-?hvVtq] [-s signal] [-c filename] [-p prefix] [-g directives]
-?,-h : 打開幫助信息
-v : 顯示版本信息並退出
-V : 顯示版本和配置選項信息,然后退出
-t : 檢測配置文件是否有語法錯誤,然后退出
-q : 在檢測配置文件期間屏蔽非錯誤信息
-s signal : 給一個 nginx 主進程發送信號:stop(強制停止), quit(優雅退出), reopen(重啟), reload(重新加載配置文件)
-p prefix : 設置前綴路徑(默認是:/usr/share/nginx/)
-c filename : 設置配置文件(默認是:/etc/nginx/nginx.conf)
-g directives : 設置配置文件外的全局指令
Docker部署nginx
$ docker run --name runoob-nginx-test -p 8081:80 -d nginx
-
runoob-nginx-test容器名稱。 -
the
-d設置容器在在后台一直運行。 -
the
-p端口進行映射,將本地 8081 端口映射到容器內部的 80 端口。
nginx 部署
首先,創建目錄 nginx, 用於存放后面的相關東西。
$ mkdir -p ~/nginx/www ~/nginx/logs ~/nginx/conf
拷貝容器內 Nginx 默認配置文件到本地當前目錄下的 conf 目錄,容器 ID 可以查看 docker ps 命令輸入中的第一列:
docker cp 6dd4380ba708:/etc/nginx/nginx.conf ~/nginx/conf
-
www: 目錄將映射為 nginx 容器配置的虛擬目錄。
-
logs: 目錄將映射為 nginx 容器的日志目錄。
-
conf: 目錄里的配置文件將映射為 nginx 容器的配置文件。
部署命令
$ docker run -d -p 8082:80 --name runoob-nginx-test-web -v ~/nginx/www:/usr/share/nginx/html -v ~/nginx/conf/nginx.conf:/etc/nginx/nginx.conf -v ~/nginx/logs:/var/log/nginx nginx
命令說明:
-
-p 8082:80: 將容器的 80 端口映射到主機的 8082 端口。
-
--name runoob-nginx-test-web:將容器命名為 runoob-nginx-test-web。
-
-v ~/nginx/www:/usr/share/nginx/html:將我們自己創建的 www 目錄掛載到容器的 /usr/share/nginx/html。
-
-v ~/nginx/conf/nginx.conf:/etc/nginx/nginx.conf:將我們自己創建的 nginx.conf 掛載到容器的 /etc/nginx/nginx.conf。
-
-v ~/nginx/logs:/var/log/nginx:將我們自己創建的 logs 掛載到容器的 /var/log/nginx。
如果要重新載入 NGINX 可以使用以下命令發送 HUP 信號到容器:
$ docker kill -s HUP container-name
重啟 NGINX 容器命令:
$ docker restart container-name
