how to configure ssl to access http under the virtual host nginx

Posted by millikan at 2020-03-26

1、 Turn on SSL in the configuration file

Open the file and add the following code under the listen 80 code segment:

Listen 443; (Note: listen to port 443)

SSL on; (Note: enable SSL)

Ssl_certificate_key / www / wdlinux / nginx / conf / aitiancheng.key; (Note: SSL certificate path)

Ssl_certificate / www / wdlinux / nginx / conf / aitiancheng.crt; (Note: SSL certificate path)

2、 Open port 443 access in firewall

Tip: please delete the above notes during configuration.

Step 1: server environment, LNMP is Linux + nginx + PHP + mysql. In this article, I take my blog as an example. I use the LNMP environment built by WDCP, alicloud's lowest VPS + FREE Linux server management system (similar products and AMH have free version and charging version). Detailed operation documents can be found in the official forum for specific installation and usage.

Step 2: create your website, use the LNMP environment to create your website. If you have a website, make sure that your program can run normally under LNMP. Take WordPress for example, the pseudo-static rules of lamp and LNMP are different. Remember to switch if you have changed them.

Step 3: apply for free SSL certificate.

Step 4: configure the website SSL, find the nginx configuration file of the website you need to configure SSL. Take WDCP as an example, add the following code to the website only configuration file server in the directory / www / wdlinux / nginx / conf / Vhost /. At the same time, in order to facilitate management, you need to upload the SSL certificate under nginx to the directory / www / wdlinux / nginx / conf /. Different management systems or The directory of manually configured LNMP environment is different. Please adjust it according to your actual situation.

Because SSL is not accessing port 80 of traditional websites, but port 443 needs to be added to the configuration file. For the convenience of those who don't know where to put the above in the configuration file, the following will post the complete configuration file of our website, which can be modified according to your actual situation.

Finally, you need to open port 443 in the WDCP background.

The above basically completes the SSL certificate deployment.

Great! ()