Start nginxssl configuration based on docker

Start nginxssl configuration based on docker

Prerequisites

  • A cloud server (centOS of Alibaba Cloud, Tencent Cloud, etc.)
  • The server must have Docker (the installation method is not introduced here)
  • A domain name
  • ssl certificate (two files: one with key suffix and one with pem suffix; there are many ways to generate them and I will not introduce them here)

Download the latest nginx docker image

docker pull nginx:latest

Create a directory nginx to store the following related things

mkdir -p /home/nginx/www /home/nginx/logs /home/nginx/conf

Put our static HTML page in the /home/nginx/www folder;

Create a file called nginx.conf under the created /home/nginx/conf folder as follows:

user nginx;
worker_processes 1;
 
error_log /var/log/nginx/error.log warn;
pid /var/run/nginx.pid;
 
 
events {
  worker_connections 1024;
}
 
 
http {
  include /etc/nginx/mime.types;
  default_type application/octet-stream;
 
  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;
 
  sendfile on;
  #tcp_nopush on;
 
  keepalive_timeout 65;
 
  #gzip on;
 
  include /etc/nginx/conf.d/*.conf;

Deploy nginx

docker run -d -p 80:80 -p 443:443 --name nginx-server -v /home/nginx/www:/usr/share/nginx/html -v /home/nginx/conf/nginx.conf:/etc/nginx/nginx.conf -v /home/nginx/logs:/var/log/nginx nginx

Command Explanation:

-p 80:80: Map the container's port 80 to the host's port 80.

-p 443:443: Map the container's port 80 to the host's port 443.
--name nginx-server: Name the container nginx-server.

-v /home/nginx/www:/usr/share/nginx/html: mount the www directory we created to the container’s /usr/share/nginx/html.

-v /home/nginx/conf/nginx.conf:/etc/nginx/nginx.conf: mount the nginx.conf we created ourselves to the container's /etc/nginx/nginx.conf.

-v /home/nginx/logs:/var/log/nginx: mount the logs we created ourselves to the container's /var/log/nginx.

After starting, you can access our HTML page through the domain name, but it’s not over yet.

Modify nginx.conf

Insert the following content into the nginx.conf file we just created: (Note: do not restart first)

server {
  listen 443 ssl;
  server_name fightingtop.cn www.fightingtop.cn;
  root /usr/share/nginx/html;
  ssl_certificate /ssl/certificate.pem;
  ssl_certificate_key /ssl/2832429_fightingtop.cn.key;
  ssl_session_timeout 5m;
  ssl_session_cache shared:SSL:1m;
  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;
 
  location / {
    root /usr/share/nginx/html;
    index index.html index.htm;
  }
}
 
server {
  listen 80;
  server_name fightingtop.cn www.fightingtop.cn;
  rewrite ^ https://$host$1 permanent;
}

Copy the two certificate files to the nginx container

First enter the nginx container and create an ssl folder in the root directory to store the certificate

docker exec -it aa5badebd38a /bin/bash cd / mkdir ssl

Start copying certificates

docker cp /home/ssl/certificate.key aa5badebd38a:/ssl/
docker cp /home/ssl/certificate.pem aa5badebd38a:/ssl/

You're done, reboot and you're done!

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:
  • Use Docker to install Nginx and configure port forwarding problems and solutions
  • Docker deploys Nginx and configures reverse proxy
  • Docker nginx + https subdomain configuration detailed tutorial
  • How to deploy nginx with Docker and modify the configuration file
  • nginx automatically generates configuration files in docker container
  • Detailed explanation of nginx plug-in configuration and files under Docker

<<:  JavaScript to achieve click image flip effect

>>:  Web page creation question: Image file path

Recommend

MySQL 1130 exception, unable to log in remotely solution

Table of contents question: 1. Enable remote logi...

Using CSS3 to implement font color gradient

When using Animation.css, I found that the font o...

What is html file? How to open html file

HTML stands for Hypertext Markup Language. Nowada...

Specific use of Linux dirname command

01. Command Overview dirname - strip non-director...

Loading animation implemented with CSS3

Achieve results Implementation Code <h1>123...

VMware Workstation download and installation detailed tutorial

Virtual machines are very convenient testing soft...

Raspberry Pi msmtp and mutt installation and configuration tutorial

1. Install mutt sudo apt-get install mutt 2. Inst...

Detailed tutorial on using VMware WorkStation with Docker for Windows

Table of contents 1. Introduction 2. Install Dock...

How to change the system language of centos7 to simplified Chinese

illustrate When you install the system yourself, ...

25 Tools to Improve Website Usability and Conversion Rates

For a website, usability refers to whether users c...

JS implements multiple tab switching carousel

Carousel animation can improve the appearance and...

The difference between MySQL execute, executeUpdate and executeQuery

The differences among execute, executeUpdate, and...

Promise encapsulation wx.request method

The previous article introduced the implementatio...