Centos6.8+nginx build a simple HTTPS server

Source: Internet
Author: User

Here Nginx build HTTPS server, must have several requirements, the first has installed Openssl-devel, of course, this does not seem to compile Add SSL module error. If the compilation has not can refer to my previous blog, of course, Baidu and Google also a lot of information.


1, confirm that the Nginx server can run normally

Lsof-i:80

#查看80端口是否正常启用, nginx default 80 port instead of 443 port

Netstat-ntpl | grep Nginx | Wc-l
Ss-ntpl | grep nginx |wc-l

#这也是一种方法, Wc-l is the number of rows of statistical results


2. Back up the original master configuration file

CP nginx.conf Nginx.conf.https


3. Using OpenSSL to generate untrusted certificates and private keys

OpenSSL genrsa-des3-out Https_1.key 2048

#首先创建私钥, you will be prompted to enter a password, this password must be backed up, if in the production environment, the fewer people know the better, because the Nginx server normal Restart stop and other operations are password.

#genrsa: Generate RSA Key command, DES3: Secret decryption algorithm, out: The file name of the output, 2048: The length is also called size, I am still accustomed to the length.


OpenSSL req-new-x509-days 3650-key https_1.key-out https_1.crt

#利用前面的私钥创建不信任的证书 (but at least it's a certificate)

#req: Generates a certificate issuance request command,-new: Represents a new request, X509 issues a certificate in the form of A/O, indicates the number of days the certificate is valid, key specifies the private key file, out: The file name of the output


4. Modify Nginx configuration file

Note: The following actions are configured in a Server tab

worker_processes  1;events {    worker_connections  1024;} http {    include       mime.types;     default_type  application/octet-stream;    sendfile         on;    keepalive_timeout  65;     server {            listen        443;server_name localhost;sslon;ssl_certificate/usr/local/nginx/conf/ Https_1.crt;ssl_certificate_key/usr/local/nginx/conf/https_1.key;ssl_session_timeout5m;ssl_protocolssslv3tlsv1 ; ssl_prefer_server_ciphers on;        location / {             root   html;             index  index.html index.htm;         }        error_page   500 502 503  504  /50x.html;        location = /50x.html  {            root   html;         }    }}

############################################################

Listen: Listening ports

SERVER_NAME: The domain name is actually

SSL on: Enable SSL

Ssl_certificate: Indicates the path where the certificate is stored, it is recommended to use absolute path

Ssl_certificate_key: Represents the private key path, it is recommended to use absolute path

Ssl_session_timeout 5m: Indicates the lifetime of the certificate in the client cache, especially reminding that the certificate is a very expensive thing to keep.

Ssl_protocols SSLv3 TLSv1: protocol used by certificates

Ssl_prefer_server_ciphers On:slv3 and TLSV1 protocols require higher priority for server passwords than client-side passwords (I'm not sure, it's definitely an optimization parameter)

Ssl_ciphers high:!anull:! md5:! export56:! EXP: This parameter is useless because I don't know how to use it.

############################################################



5. Restart Nginx

/usr/local/nginx/sbin/nginx-s Reload

#重启完一定要查看端口情况, because not every restart can be successful.

lsof-i:443

#如果没有说明重启不成功


Tip: You can restart the killall after Nginx. The firewall will allow 443 ports instead of 80 ports.


6. Use client access to view results

650) this.width=650; "Src=" https://s5.51cto.com/wyfs02/M01/99/EA/wKiom1lOa0GT6NoPAABQt_lYmmY686.png-wh_500x0-wm_ 3-wmp_4-s_1720200185.png "title=" 2017-06-24_213556.png "alt=" Wkiom1loa0gt6nopaabqt_lymmy686.png-wh_50 "/>



Vpersoning: If the wrong place can talk about me privately, I am a novice, but I like the problem.




This article is from the "10846118" blog, please be sure to keep this source http://10856118.blog.51cto.com/10846118/1941598

Centos6.8+nginx build a simple HTTPS server

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.