Quick Start 1. Find the nginx image on Docker Hub docker search nginx 2. Pull the official Nginx image docker pull nginx 3. Find the mirror with REPOSITORY as nginx in the local mirror list docker images nginx REPOSITORY TAG IMAGE ID CREATED SIZE 4. The following command starts an Nginx container instance using the default configuration in the NGINX container: Copy the code as follows: docker run --rm --name nginx-test -p 8080:80 -d nginx The meanings of the four command line parameters of this command are as follows.
5. View the started docker container docker container ps CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 6. Access in the browser. I am using Tencent Cloud Host. Just access the public IP+port. Open http://public network ip:8080 in the browser, the effect is as follows. Deployment Service 1. Create a local directory to store Nginx related file information. mkdir -p /home/nginx/www /home/nginx/logs /home/nginx/conf in:
2. Copy the default Nginx configuration file in the container to the conf directory under the local current directory. The container ID can be viewed in the first column of the docker ps command input: docker ps CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES docker cp acb0e263dff3:/etc/nginx /home/nginx/conf 3. Stop this container docker container stop nginx-test Note the command to enter the container: docker exec -it nginx-test /bin/bash 4. Deployment Commands docker run --rm -d -p 8080:80 --name nginx-test-web \ -v /home/nginx/www:/usr/share/nginx/html \ -v /home/nginx/conf/nginx:/etc/nginx \ -v /home/nginx/logs:/var/log/nginx \ nginx Command Explanation:
5. After launching the above command, enter the /home/nginx/www directory:
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title>Nginx test !!!</title> </head> <body> <h1>My first title</h1> <p>My first paragraph. </p> </body> </html> 6. Access in browser Enter http://public network ip:8080/ in the browser, the output is as follows. If a 403 error appears during access, it should be that the index.html file has insufficient permissions. Just set it to 644. Support HTTPS, HTTP2 1. Create a subdirectory certs in the directory /home/nginx/conf/nginx mkidr certs 2. Generate a certificate openssl req \ -x509 \ -nodes \ -days 365 \ -newkey rsa:2048 \ -keyout example.key \ -out example.crt The meanings of the parameters in the above command are as follows.
If the directory is created successfully, two more files will be created: example.key and example.crt. 3.HTTPS configuration Create the https.conf file in the /home/nginx/conf/nginx/conf.d directory and write the following: server { listen 443 ssl http2; server_name localhost; ssl on; ssl_certificate /etc/nginx/certs/example.crt; ssl_certificate_key /etc/nginx/certs/example.key; ssl_session_timeout 5m; ssl_ciphers HIGH:!aNULL:!MD5; ssl_protocols SSLv3 TLSv1 TLSv1.1 TLSv1.2; ssl_prefer_server_ciphers on; location / { root /usr/share/nginx/html; index index.html index.htm; } } 4. Deployment Service docker run --rm -d -p 8080:80 -p 8081:443 --name nginx-test-web \ -v /home/nginx/www:/usr/share/nginx/html \ -v /home/nginx/conf/nginx:/etc/nginx \ -v /home/nginx/logs:/var/log/nginx \ nginx 5. Quick Test
The above is the full content of this article. I hope it will be helpful for everyone’s study. I also hope that everyone will support 123WORDPRESS.COM. You may also be interested in:
|
<<: How to get the maximum or minimum value of a row in sql
>>: HTML table tag tutorial (12): border style attribute FRAME
MySQL partitioning is helpful for managing very l...
The vertically adjacent edges of two or more bloc...
Install TomCat on Windows This article will intro...
Problem Description I created three virtual machi...
Preface: As a giant in the IT industry, Microsoft...
Table of contents 1. Mutex 1. Initialization of m...
Table of contents 1. redo log (transaction log of...
The mysql on the server is installed with version...
This tutorial introduces the application of vario...
This article example shares the specific code of ...
CSS issues about background gradient and automati...
1. Mirror images disappear in 50 and 93 [root@h50...
Table of contents 1. Modular concept 2. Modulariz...
Table of contents Preface The principle of browse...
After obtaining the system time using Java and st...