How to configure Nginx server https
Apply for a certificate
There are currently many organizations on the Internet that provide personal free SSL certificates, with validity periods ranging from several months to several years. Take startssl: https://www.startssl.com as an example. After successful application, it will be valid for 3 years and can be renewed for free after expiration.
The specific application process is also very simple.
After registering and logging in, select certificates wizard >> dv ssl certificate to apply for a free ssl certificate.
After verifying the domain name through email, then generate the csr of the ssl certificate in your own server, Remember the secret to generate the input , you will use it later:
openssl req -newkey rsa:2048 -keyout weizhimiao.cn.key -out weizhimiao.cn.csr
will generate The certificate is placed in the specified directory where the certificate is stored, such as /data/secret/
. View the contents of the certificate weizhimiao.csr
, copy the contents to the certificate signing request (csr) section of the page, and submit the page.
Download the generated certificate and select the corresponding web server (nginx, 1_weizhimiao.cn_bundle.crt), so that we have both the private key and the public key.
1_weizhimiao.cn_bundle.crt (public key)
weizhimiao.cn.key (private key)
nginx configuration (add https to the specified domain name)
nginx.conf current configuration
... http { ... include /etc/nginx/conf.d/*.conf; server { ... } }
./conf.d/weizhimiao.cn.conf added
server{ listen 443 ssl; server_name weizhimiao.cn; ssl_certificate /data/secret/1_weizhimiao.cn_bundle.crt; ssl_certificate_key /data/secret/weizhimiao.cn.key; ssl_prefer_server_ciphers on; ssl_protocols tlsv1 tlsv1.1 tlsv1.2; ssl_ciphers 'keecdh+ecdsa+aes128 keecdh+ecdsa+aes256 keecdh+aes128 keecdh+aes256 kedh+aes128 kedh+aes256 des-cbc3-sha +sha !anull !enull !low !md5 !exp !dss !psk !srp !kecdh !camellia !rc4 !seed'; add_header strict-transport-security 'max-age=31536000; preload'; add_header x-frame-options deny; ssl_session_cache shared:ssl:10m; ssl_session_timeout 10m; keepalive_timeout 70; ssl_dhparam /data/secret/dhparam.pem; add_header x-content-type-options nosniff; add_header x-xss-protection 1; root /data/www/weizhimiao.cn; index index.html; location / { } }
Note:
A /data/secret/dhparam.pem
file is used in the configuration. This file is a key file in pem format and is used for tls in session. Used to enhance the security of ssl. The method to generate this file,
cd /data/secret/ openssl dhparam 2048 -out dhparam.pem
will redirect the original access to port 80. Add
server{ listen 80; server_name weizhimiao.cn; return 301 https://weizhimiao.cn$request_uri; }
test
to ./conf.d/weizhimiao.cn.conf to check whether there are syntax errors in the configuration file. You need to enter the previous input when generating the public key. password.
nginx -t enter pem pass phrase: nginx: the configuration file /etc/nginx/nginx.conf syntax is ok nginx: configuration file /etc/nginx/nginx.conf test is successful
Restart nginx (remember, reload does not work)
nginx -s stop enter pem pass phrase: nginx enter pem pass phrase:
Visit weizhimiao.cn with the browser to see if it takes effect.
In addition, after nginx is configured with a security certificate, nginx requires a password for each reload, stop, and other operations.
You can generate a decrypted key file to replace the original key file.
cd /data/secret/ openssl rsa -in weizhimiao.cn.key -out weizhimiao.cn.key.unsecure
Replace the weizhimiao.cn.key
file in weizhimiao.cn.conf
.
server { ... ssl_certificate /data/secret/1_weizhimiao.cn_bundle.crt; ssl_certificate_key /data/secret/weizhimiao.cn.key.unsecure; ... }
Every time after reload, it will not You need to enter your password.
Finally, use ssllabs to test.
result
The above is the detailed content of How to configure Nginx server https. For more information, please follow other related articles on the PHP Chinese website!

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

You can query the Docker container name by following the steps: List all containers (docker ps). Filter the container list (using the grep command). Gets the container name (located in the "NAMES" column).

How to configure Nginx in Windows? Install Nginx and create a virtual host configuration. Modify the main configuration file and include the virtual host configuration. Start or reload Nginx. Test the configuration and view the website. Selectively enable SSL and configure SSL certificates. Selectively set the firewall to allow port 80 and 443 traffic.

How to confirm whether Nginx is started: 1. Use the command line: systemctl status nginx (Linux/Unix), netstat -ano | findstr 80 (Windows); 2. Check whether port 80 is open; 3. Check the Nginx startup message in the system log; 4. Use third-party tools, such as Nagios, Zabbix, and Icinga.

Docker container startup steps: Pull the container image: Run "docker pull [mirror name]". Create a container: Use "docker create [options] [mirror name] [commands and parameters]". Start the container: Execute "docker start [Container name or ID]". Check container status: Verify that the container is running with "docker ps".

How to configure an Nginx domain name on a cloud server: Create an A record pointing to the public IP address of the cloud server. Add virtual host blocks in the Nginx configuration file, specifying the listening port, domain name, and website root directory. Restart Nginx to apply the changes. Access the domain name test configuration. Other notes: Install the SSL certificate to enable HTTPS, ensure that the firewall allows port 80 traffic, and wait for DNS resolution to take effect.

The methods that can query the Nginx version are: use the nginx -v command; view the version directive in the nginx.conf file; open the Nginx error page and view the page title.

Create a container in Docker: 1. Pull the image: docker pull [mirror name] 2. Create a container: docker run [Options] [mirror name] [Command] 3. Start the container: docker start [Container name]

Starting an Nginx server requires different steps according to different operating systems: Linux/Unix system: Install the Nginx package (for example, using apt-get or yum). Use systemctl to start an Nginx service (for example, sudo systemctl start nginx). Windows system: Download and install Windows binary files. Start Nginx using the nginx.exe executable (for example, nginx.exe -c conf\nginx.conf). No matter which operating system you use, you can access the server IP
