Nginx is a high-performance website server and reverse proxy server, as well as an IMAP, POP3, SMTP and other mail proxy servers; nginx can be used as a website server to publish websites, and nginx can be used as a reverse proxy to achieve load balancing. This article describes how to use Nginx to deploy https websites and configure address rewriting in the centos6.9 environment. 1.Environment preparation: one centos6.9 host, turn off firewall and Selinux Install dependency packages: Create nginx user: useradd -M -s /sbin/nologin nginx #Do not create a home directory for the Nginx user, no interactive shell tar -xf nginx-1.8.0.tar.gz cd nginx-1.8.0 ./configure --user=nginx --group=nginx --prefix=/usr/local/nginx --with-http_stub_status_module --with-http_ssl_module (--with-http_ssl_module specifies the installation of the security module, which must be installed when deploying https websites. The /usr/local/nginx directory does not need to be created in advance) make && make install cd /usr/local/nginx ls /usr/local/nginx conf #Store nginx configuration files logs #Store service logs and PID files html #Store website pages sbin #Executable main program directory 2. Link the startup program to the /usr/sbin/ path:
nginx command: nginx # Start the service nginx -s stop # Shut down the service nginx -s reload # Reload the configuration file nginx -t # Test the configuration file nginx -v # View the version information nginx -V # View the compilation options Start service: nginx Test the website through IP to see if it can be accessed normally. If the following page appears, it means the website configuration is successful (there is only one default http page at this time): 3. Use openssl to generate a certificate and configure the https website: cd /usr/local/nginx/conf openssl genrsa -out my.key #Generate a private key for the RSA algorithm openssl req -new -x509 -key my.key -out my.crt #Generate a sub-signature certificate, equivalent to a public key Modify the nginx configuration file to specify the location of the certificate: vim /usr/local/nginx/conf/nginx.conf ... ... server { listen 443 ssl; server_name www.test.com; ssl_certificate my.crt; #Specify the certificate location. By default, it will be searched in the current directory. ssl_certificate_key my.key; #Specify the private key location location / { root /var/www/html; #Specify the root path of web page files, separate from the http website path, to facilitate the distinction index index.html; } } After the modification is completed, reload the configuration file: mkdir -p /var/www/html echo "ssl test" >/var/www/html/index.html 4. Perform access verification: The effect of http access is as follows: The effect of https access is as follows: 5. Configure http address rewriting so that the client automatically jumps to https when accessing http: vim /usr/local/nginx/conf/nginx.conf ... ... server { listen 80; server_name www.test.com; rewrite ^(.*)$ https://${server_name}$1 permanent; #When receiving an http access request, redirect to https location / { root html; index index.html index.htm; } After the modification is completed, reload the configuration file: 6. Visit again to verify: When accessing a web page through the http protocol, it will automatically jump to https: If the domain name is not resolved, please add a hosts record and write the correspondence between the domain name and IP into the hosts file. Summarize The above is the full content of this article. I hope that the content of this article will have certain reference learning value for your study or work. Thank you for your support of 123WORDPRESS.COM. If you want to learn more about this, please check out the following links You may also be interested in:
|
<<: Detailed explanation of this pointing problem in JavaScript
>>: How to install MySQL database on Debian 9 system
This article example shares the specific code of ...
This article example shares the specific code of ...
Use js to control the light switch for your refer...
Table of contents Mainly used Postman functions D...
Project scenario: When running the Vue project, t...
Process 1: with return value: drop procedure if e...
background Now the company's projects are dev...
Copy code The code is as follows: <!--[if !IE]...
This article example shares the specific code of ...
1. RPM version installation Check if there are ot...
I recently used the input size and maxlength attri...
1. scroll-view When using vertical scrolling, you...
Follow the official tutorial, download the instal...
1. Introduction Is it considered rehashing old st...
1. Optimize Nginx concurrency [root@proxy ~]# ab ...