Nginx common command and docker nginx common command

Deploy nginx

nginx #Open nginx
nginx -t #Test the configuration file for syntax errors< br>nginx -s reopen #restart Nginx
nginx -s reload #Reload the Nginx configuration file, and then restart Nginx in an elegant way
nginx -s stop #Force stop Nginx service
nginx -s quit # Stop the Nginx service gracefully (that is, stop the service after all the requests are processed)


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


-?,-h: Open help information
-v: Display version information and exit
-V: Display version and configuration options information, and then exit
-t: Check whether the configuration file has syntax errors, and then exit
-q: Mask non-error information during configuration file detection
– s signal: Send a signal to a nginx main process: stop (forced stop), quit (graceful exit), reopen (restart), reload (reload configuration file)
-p prefix: Set the prefix path (default: /usr/share/nginx/)
-c filename: Set configuration file (default: /etc/nginx/nginx.conf)
-g directives: Set global directives outside the configuration file






Docker deployment nginx

$ docker run --name runoob< span class="pun">-nginx-test -p 8081:80 -d nginx
  • runoob-nginx-test Container name.

  • the -d Set the container to always run in the background.

  • the -p The port is mapped, and the local port 8081 is mapped to the port 80 inside the container.

nginx deployment

First, create a directory nginx to store the following related things.

$ mkdir p ~/nginx/www ~/nginx/logs ~/nginx/ conf< /p>

Copy the default configuration file of Nginx in the container to the conf directory under the local current directory. The container ID can be viewed The first column in the docker ps command input:

docker cp 6dd4380ba708:/etc/nginx/nginx.conf ~< span class="str">/nginx/conf< /span>

  • www: The directory will be mapped to the virtual configuration of the nginx container content.

  • logs: directory Will be mapped to the log directory of the nginx container.

  • conf: directory The configuration file in will be mapped to the configuration file of the nginx container.

Deployment command

$ docker run d p 8082:80 name runoobnginxtestweb v ~/nginx/www:/usr/share/nginx /html v ~/nginx/conf/nginx.conf:/etc/nginx/nginx.conf v ~/nginx/logs:/var/log/nginx nginx< /span>< /span>

< p>Command description:

  • -p 8082:80: Map port 80 of the container to port 8082 of the host.

  • –name runoob-nginx- test-web:Name the container runoob-nginx-test-web.

  • -v ~/nginx/www :/usr/share/nginx/html: Mount the www directory that we created to the container’s /usr/share/nginx/html.

  • -v ~/nginx/conf /nginx.conf:/etc/nginx/nginx.conf: Mount the nginx.conf we created to the container’s /etc/nginx/nginx.conf.

  • -v ~/nginx/logs :/var/log/nginx: Mount the logs we created to the container’s /var/log/nginx.

    If you want to reload NGINX, you can use the following command to send the HUP signal to the container:< /span>

    $ docker kill s HUP containername

    Restart NGINX container command:

    $ docker restart containername

Leave a Comment

Your email address will not be published.