How to configure nginx to use ssl module to support HTTPS access
Background:
WeChat applet is used in project development, but the server configuration URL must be https, so the ssl module of nginx needs to be configured to support https access, that is to say To make a website with a domain name of dmsdbj.com, it is required to access it through https://dmsdbj.com.
ssl is called secure socket layer in English. SSL is a digital certificate that uses the SSL protocol to establish a secure channel between the browser and the web server. Data information is securely transmitted between the client and the server.
Prerequisite:
1. To configure the SSL module, you first need a CA certificate. The CA certificate can be issued manually or applied for on Alibaba Cloud. I applied for the certificate on Alibaba Cloud. (For manual issuance, please refer to the link at the bottom of the article)
2. The ssl module is not installed by default. If you want to use this module, you need to specify the –with-http_ssl_module parameter when compiling nginx.
Alibaba Cloud purchase ca certificate
Operation steps:
1. Download the ca certificate
1. Log in to Alibaba Cloud, Select "Console" - "Products and Services", and select "ca Certificate Service (Data Security)" in the "Security (Cloud Shield)" column.
2. Click "Download" on the purchased certificate, and select "nginx/tengine" on the newly opened page. Click "Download certificate for nginx".
2. Install the certificate in the nginx configuration file
File description: 1. The certificate file "certificate name.pem'' contains two sections of content. Please do not delete any content. 2. If it is a csr created by the certificate system, it also contains: the certificate private key file "certificate name.key". (1) In Create a cert folder in the directory where the nginx configuration file is located, and copy all the downloaded files to the cert directory. If you create a csr file yourself when applying for a certificate, please put the corresponding private key file in the cert directory and name it is "certificate name.key";
(2) Open the nginx.conf file in the conf directory under the nginx installation directory, find:
# https server # #server { # listen 443; # server_name localhost; # ssl on; # ssl_certificate cert.pem; # ssl_certificate_key cert.key; # ssl_session_timeout 5m; # ssl_protocols sslv2 sslv3 tlsv1; # ssl_ciphers all:!adh:!export56:rc4+rsa:+high:+medium:+low:+sslv2:+exp; # ssl_prefer_server_ciphers on; # location / { # # #} #}
(3) Modify it to (the following attributes The attributes starting with ssl are directly related to the certificate configuration. Please copy or adjust other attributes based on your actual situation):
server { listen 443; server_name localhost; ssl on; root html; index index.html index.htm; ssl_certificate cert/证书名称.pem; ssl_certificate_key cert/证书名称.key; ssl_session_timeout 5m; 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 html; index index.html index.htm; } }
Save and exit.
(4) Restart nginx.
nginx -s reload
(5) Access your site through https and test the installation and configuration of the site certificate. Enter https://dmsdbj.com in the browser, as shown in the figure below, indicating that the configuration is successful.
Problems encountered during the installation process
Error 1:
nginx: [emerg ] unknown directive "ssl" in /usr/local/nginx/conf/nginx.conf:151
Solution:
This error may be caused by two situations :
Case one: The configuration file format is incorrect.
Solution reference link:
Case two: The ssl module is not installed
Default situation The ssl module is not installed. If you want to use this module, you need to specify the --with-http_ssl_module parameter when compiling nginx. This situation will also cause error 2.
Solution:
nginx lacks the http_ssl_module module. When compiling and installing, just bring the --with-http_ssl_module configuration. But the current situation is that my nginx has already been installed. How to add the module is actually very simple. Read on: Note: My nginx installation directory is the /usr/local/nginx directory, and my source code package is in the /usr/local/src/nginx-1.3.6 directory
(1) Switch to the source code package:
cd /root/nginx-1.13.6
(2) Configuration information:
./configure --prefix=/usr/local/nginx --with-http_stub_status_module --with-http_ssl_module
(3) After the configuration is completed, run make to compile. Do not perform make install, otherwise it will overwrite the installation.
mark
(4) Then back up the original installed nginx
cp /usr/local/nginx/sbin/nginx /usr/local/nginx/sbin/nginx.bak
(5) Stop nginx, just use the normal command nginx -s stop
nginx -s stop
If you turn it off If not, just kill the process directly. ps aux | grep process name to view the pid number occupied by the process.
ps aux|grep nginx
Just kill the detected pid. The kill -9 pid command is used to terminate the process. You must first kill the pid corresponding to root before you can proceed with the following three nobody pids.
kill -9 10922 kill -9 28276 kill -9 28277 kill -9 28278
(6) Overwrite the original nginx with the just compiled nginx
cp ./objs/nginx /usr/local/nginx/sbin/
(7) Start nginx
nginx
(8) Use the following command to check whether Already joined successfully.
nginx -v
Error two:
nginx: [emerg] the "ssl" parameter requires ngx_http_ssl_module in /usr/local/nginx/conf/nginx.conf:148
Solution:
For the solution to this situation, please refer to the solution to the second situation of error 1.
Error three:
stoping nginx... nginx: [emerg] bio_new_file("/usr/local/nginx/conf/cert/214291778530222. pem") failed (ssl: error:02001002:system library:fopen:no such file or directory:fopen('/usr/local/nginx/conf/cert/214291778530222.pem','r') error:2006d080:bio routines:bio_new_file:no such file) failed. use force-quit
Solution:
This may be because the certificate path is not stored in the correct location It is caused correctly, and as long as the absolute path is written, an error will be reported, regardless of Windows or Linux.
Put the certificate file in the directory where nginx.conf is located.
The above is the detailed content of How to configure nginx to use ssl module to support HTTPS access. For more information, please follow other related articles on the PHP Chinese website!

NGINX can improve website performance and reliability by: 1. Process static content as a web server; 2. forward requests as a reverse proxy server; 3. allocate requests as a load balancer; 4. Reduce backend pressure as a cache server. NGINX can significantly improve website performance through configuration optimizations such as enabling Gzip compression and adjusting connection pooling.

NGINXserveswebcontentandactsasareverseproxy,loadbalancer,andmore.1)ItefficientlyservesstaticcontentlikeHTMLandimages.2)Itfunctionsasareverseproxyandloadbalancer,distributingtrafficacrossservers.3)NGINXenhancesperformancethroughcaching.4)Itofferssecur

NGINXUnit simplifies application deployment with dynamic configuration and multilingual support. 1) Dynamic configuration can be modified without restarting the server. 2) Supports multiple programming languages, such as Python, PHP, and Java. 3) Adopt asynchronous non-blocking I/O model to improve high concurrency processing performance.

NGINX initially solved the C10K problem and has now developed into an all-rounder who handles load balancing, reverse proxying and API gateways. 1) It is well-known for event-driven and non-blocking architectures and is suitable for high concurrency. 2) NGINX can be used as an HTTP and reverse proxy server, supporting IMAP/POP3. 3) Its working principle is based on event-driven and asynchronous I/O models, improving performance. 4) Basic usage includes configuring virtual hosts and load balancing, and advanced usage involves complex load balancing and caching strategies. 5) Common errors include configuration syntax errors and permission issues, and debugging skills include using nginx-t command and stub_status module. 6) Performance optimization suggestions include adjusting worker parameters, using gzip compression and

Diagnosis and solutions for common errors of Nginx include: 1. View log files, 2. Adjust configuration files, 3. Optimize performance. By analyzing logs, adjusting timeout settings and optimizing cache and load balancing, errors such as 404, 502, 504 can be effectively resolved to improve website stability and performance.

NGINXUnitischosenfordeployingapplicationsduetoitsflexibility,easeofuse,andabilitytohandledynamicapplications.1)ItsupportsmultipleprogramminglanguageslikePython,PHP,Node.js,andJava.2)Itallowsdynamicreconfigurationwithoutdowntime.3)ItusesJSONforconfigu

NGINX can be used to serve files and manage traffic. 1) Configure NGINX service static files: define the listening port and file directory. 2) Implement load balancing and traffic management: Use upstream module and cache policies to optimize performance.

NGINX is suitable for handling high concurrency and static content, while Apache is suitable for dynamic content and complex URL rewrites. 1.NGINX adopts an event-driven model, suitable for high concurrency. 2. Apache uses process or thread model, which is suitable for dynamic content. 3. NGINX configuration is simple, Apache configuration is complex but more flexible.


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

mPDF
mPDF is a PHP library that can generate PDF files from UTF-8 encoded HTML. The original author, Ian Back, wrote mPDF to output PDF files "on the fly" from his website and handle different languages. It is slower than original scripts like HTML2FPDF and produces larger files when using Unicode fonts, but supports CSS styles etc. and has a lot of enhancements. Supports almost all languages, including RTL (Arabic and Hebrew) and CJK (Chinese, Japanese and Korean). Supports nested block-level elements (such as P, DIV),

Zend Studio 13.0.1
Powerful PHP integrated development environment

SecLists
SecLists is the ultimate security tester's companion. It is a collection of various types of lists that are frequently used during security assessments, all in one place. SecLists helps make security testing more efficient and productive by conveniently providing all the lists a security tester might need. List types include usernames, passwords, URLs, fuzzing payloads, sensitive data patterns, web shells, and more. The tester can simply pull this repository onto a new test machine and he will have access to every type of list he needs.

MantisBT
Mantis is an easy-to-deploy web-based defect tracking tool designed to aid in product defect tracking. It requires PHP, MySQL and a web server. Check out our demo and hosting services.

DVWA
Damn Vulnerable Web App (DVWA) is a PHP/MySQL web application that is very vulnerable. Its main goals are to be an aid for security professionals to test their skills and tools in a legal environment, to help web developers better understand the process of securing web applications, and to help teachers/students teach/learn in a classroom environment Web application security. The goal of DVWA is to practice some of the most common web vulnerabilities through a simple and straightforward interface, with varying degrees of difficulty. Please note that this software
