nginx經常使用命令與docker nginx經常使用命令

部署nginx

nginx #打開 nginx
nginx -t    #測試配置文件是否有語法錯誤
nginx -s reopen #重啓Nginx
nginx -s reload   #從新加載Nginx配置文件,而後以優雅的方式重啓Nginx
nginx -s stop  #強制中止Nginx服務
nginx -s quit  #優雅地中止Nginx服務(即處理完全部請求後再中止服務)html

 


nginx [-?hvVtq] [-s signal] [-c filename] [-p prefix] [-g directives]nginx

 

-?,-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   : 設置配置文件外的全局指令web






Docker部署nginx

$ docker run --name runoob-nginx-test -p 8081:80 -d nginx
  • runoob-nginx-test 容器名稱。docker

  • the -d設置容器在在後臺一直運行。測試

  • the -p 端口進行映射,將本地 8081 端口映射到容器內部的 80 端口。ui

nginx 部署

首先,建立目錄 nginx, 用於存放後面的相關東西。spa

$ mkdir -p ~/nginx/www ~/nginx/logs ~/nginx/confrest

拷貝容器內 Nginx 默認配置文件到本地當前目錄下的 conf 目錄,容器 ID 能夠查看 docker ps 命令輸入中的第一列:日誌

docker cp 6dd4380ba708:/etc/nginx/nginx.conf ~/nginx/confcode

  • 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

相關文章
相關標籤/搜索