Nginx Configuration HTTPS

Source: Internet
Author: User

Nginx Configuration HTTPS

Load Balancing

Nginx HTTPS protocol requires the support of the SSL module, we use the--with-http_ssl_module parameter to add the SSL module when compiling nginx. Also need the server private key, the server certificate, if is the company external environment, this certificate needs to purchase the third party's authoritative certificate, otherwise the user experience does not have the safeguard; here I only use and test on my VPS.

Note: If you are purchasing a third-party service certificate, you only need to refer to 1.3-1.4 configuration information to complete the Enterprise SSL configuration practice.

Check that the Nginx SSL module is installed
[[Email protected]~]#/application/nginx/sbin/nginx-v
Nginx version:nginx/1.6.3
Built by GCC 4.4.7 20120313 (Red Hat 4.4.7-16) (GCC)
TLS SNI Support Enabled
Configure arguments:--prefix=/application/nginx-1.6.3--user=nginx--group=nginx--with-http_ssl_module--with-http _stub_status_module

Preparing the private key and certificate

Create a server private key

[[email protected]~]# cd/application/nginx/conf/
[[email protected] conf]# mkdir key
[[email protected] conf]# cd key/
[[email protected] key]# OpenSSL genrsa-des3-out Server.key 1024x768
Generating RSA private key, 1024x768 bit long modulus
. ++++++
... ++++++
E is 65537 (0x10001)
Enter pass phrase for Server.key: Enter password
Verifying-enter pass phrase for Server.key: Re-enter the password
# # #1.2.2 Issuing a certificate
[[email protected] key]# OpenSSL req-new-key server.key-out SERVER.CSR
Enter Pass phrase for Server.key: the password you just set
you is about to is asked to Enter information that'll be incorporated< Br>into your certificate request.
What's about-is called a distinguished Name or a DN.
There was quite a few fields and you CA n leave some blank
for some fields there would be a default value,
If you enter '. ', the field would be is left BLANK.
...........................

Country Name (2 letter code) [XX]:CN (country)
State or province name (full name) []:bj (province)
Locality Name (eg, city) [Default CITY]:BJ
Organization Name (eg, company) [Default Corporate LTD]:SDU
Organizational Unit Name (eg, section) []:sa (department)
Common name (eg, your name or your server ' s hostname) []:xubusi (domain name, must be entered)
email address []:[email protected] (email)

Please enter the following ' extra ' attributes
To is sent with your certificate request
A Challenge Password []:
An optional company name []:


Remove the server private key password

[email protected] key]# CP Server.key Server.key.ori
[email protected] key]# OpenSSL rsa-in server.key.ori-out server.key
Enter Pass phrase for Server.key.ori:
Writing RSA Key


Generate a self-signed certificate using a signature request certificate and private key

[email protected] key]# OpenSSL x509-req-days 365-in server.csr-signkey server.key-out server.crt
Signature OK
Subject=/c=cn/st=bj/l=bj/o=sdu/ou=sa/cn=xubusi/[email protected]
Getting Private Key


Open Nginx SSL

[Email protected] ~]# cat/application/nginx/conf/vhosts/www.conf
server {
server_nameblog.xuliangwei.com;
#listen 80;
Listen 443;
SSL on;
Ssl_certificate KEY/SERVER.CRT;
Ssl_certificate_key Key/server.key;

Location/{
Roothtml/blog;
Index index.php index.html index.htm;
Access_log/app/logs/blog.xuliangwei.log main;
}
}


Restart Nginx in effect

[Email protected] ~]#/application/nginx/sbin/nginx-s Reload
[Email protected] ~]# Netstat-lntup|grep 443
TCP 0 0 0.0.0.0:443 0.0.0.0:* LISTEN 1711/nginx


Test HTTPS

Since the certificate was issued by a non-third-party authority and issued by us, the browser warns that a commercial third-party signed certificate must be used if the external business requires encryption.

Must access https://blog.xuliangwei.com

Configuring redirection 80 port to 443 port

The above configuration has a bad place, if the user forgot to use HTTPS or 443 port, then will be error, so we need 80 port access to 443 port and use SSL encrypted access.

You only need to add one server segment, using 301 permanent redirection.

[Email protected] ~]# tail-5/application/nginx/conf/vhosts/www.conf
server {
Listen 80;
server_name blog.xuliangwei.com;
Rewrite ^ (. *) https://$server _name$1 permanent;
}
[Email protected] ~]#/application/nginx/sbin/nginx-t
Nginx:the configuration file/application/nginx-1.6.3/conf/nginx.conf syntax is OK
Nginx:configuration file/application/nginx-1.6.3/conf/nginx.conf Test is successful
[Email protected] ~]#/application/nginx/sbin/nginx-s Reload


Input blog.xuliangwei.com Auto Jump HTTPS

Nginx Configuration HTTPS

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.