A method for configuring HTTPS protocol access under Linux Nginx _linux

Source: Internet
Author: User

First, configure Nginx to support HTTPS protocol access, you need to compile the installation Nginx to add the corresponding modules --with-http_ssl_module

View Nginx Compilation parameters:/usr/local/nginx/sbin/nginx-v

As shown below:

Configure arguments:--prefix=/usr/local/nginx--with-google_perftools_module--without-http_memcached_module-- User=www--group=www--with-http_stub_status_module--with-http_sub_module--with-http_ssl_module--with-http_ Gzip_static_module --with-openssl=/usr/local/src/openssl-1.0.1h--with-zlib=/usr/local/src/zlib-1.2.8-- with-pcre=/usr/local/src/pcre-8.35

If you do not--with-http_gzip_static_module this parameter, you need to edit the Nginx again

Second, firewall open HTTPS protocol default port 443

Vi/etc/sysconfig/iptables #编辑防火墙配置文件, add the following code

-A input-m state--state new-m tcp-p TCP--dport 443-j ACCEPT

: wq! #保存退出

Service iptables restart #重启防火墙

Third, create HTTPS certificate

Make sure OpenSSL and Openssl-devel are installed on the machine

Yum install OpenSSL openssl-devel #CentOS使用yum命令安装

Mkdir/usr/local/nginx/conf/ssl #创建证书存放目录

Cd/usr/local/nginx/conf/ssl #进入目录

Create server private key: OpenSSL genrsa-des3-out server.key 1024 #根据提示输入证书口令

To create a certificate (CSR) for a signing request:OpenSSL req-new-key server.key-out server.csr #输入上面设置的口令

#根据提示输入相应的信息

Country Name (2 letter code) [XX]:CN #国家

State or province Name (full name) []:zhejiang #省份

Locality Name (eg, city) [Default City]:hangzhou #城市

Organization Name (eg, company) [Default company Ltd]:osyunwei #公司

Organizational unit Name (eg, section) []:sys #部门

Common name (eg, your name or your server ' s hostname) []:osyunwei #主机名称

Email address []:[email protected] #邮箱

Please enter the following ' extra ' attributes

To is sent with your certificate request

A Challenge Password []:123456 #证书请求密钥, the CA must enter the password when it reads the certificate

A optional company name []:osyunwei #公司名称, the CA needs to enter a password when it reads the certificate

OpenSSL rsa-in server.key-out server_nopassword.key #对key进行解密

OpenSSL x509-req-days 365-in server.csr-signkey server_nopassword.key-out server.crt

#标记证书使用上述私钥和CSR

Iv. Modify the Nginx configuration file and load the SSL certificate

vi/usr/local/nginx/conf/nginx.conf #编辑

Listen 80;

Listen 443;

SSL on;

SSL_CERTIFICATE/USR/LOCAL/NGINX/CONF/SSL/SERVER.CRT;

Ssl_certificate_key/usr/local/nginx/conf/ssl/server_nopassword.key;

Fastcgi_param HTTPS $https If_not_empty; #有https协议时自动使用https, otherwise ignore this parameter.

: wq! #保存退出

Service nginx Restart #重启nginx

Rewrite ^ (. *) https://www.osyunwei.com$1 permanent; #可以把http协议重定向到https上面

Open the URL using the HTTPS protocol, as shown in the following illustration:

At this point, Linux nginx Configure HTTPS protocol access to complete.

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.