Configure https for nginx

Source: Internet
Author: User
: This article describes how to configure https for nginx. if you are interested in the PHP Tutorial, refer to it. Recently, the login system was developed. due to password-related issues, requests must be made in https mode, while nginx on the front end of the online system has an authenticated digital certificate. Therefore, our https requests can be parsed online and returned successfully, however, in the Test environment, directly configure the domain name host and return 404.

Therefore, you must configure https-related content on your own.

First, generate a certificate-related file and check the information on the Internet as follows:

# Generate an RSA key
$ Openssl genrsa-des3-out my. key 1024

# Copy a key file that does not require password input
$ Openssl rsa-in my. key-out my_nopass.key

# Generate a certificate request
$ Openssl req-new-key my. key-out my. csr

# Self-issuing certificate
$ Openssl x509-req-days 365-in my. csr-signkey my. key-out my. crt
The 3rd command is used to generate a certificate request, prompting you to enter the province, city, domain name information, etc. what's important is that email must be your domain name suffix. In this way, there is a csr file, which is the csr file when it is submitted to the ssl provider. Of course, I did not apply for a certificate from the certificate provider here, but issued a certificate in step 1.

In this way, you can get a certificate of your own.

Second, enable https in nginx.

Server {
Server_name you.domain.com;
Listen 443;
Ssl on;
Ssl_certificate/opt/conf/nginx/my. crt;
Ssl_certificate_key/opt/conf/nginx/my_nopass.key;
Location /{
Proxy_pass http: // resin-core-webapp;
Include/opt/conf/nginx/proxy-resin.conf;
Client_max_body_size 50 m;
Xss_get on;
Xss_callback_arg 'callback'; // this line does not exist. jsonp cannot be supported.

// If this row does not exist, the frontend cannot obtain the returned data
Add_header 'access-Control-Allow-origin''' $ http_origin ';

// It is added together with the previous row. it is unknown what will happen
Add_header 'access-Control-Allow-Credentials ''true ';

// It is added together with the previous line. it is unknown what will happen
Add_header 'access-Control-Allow-headers ''*';
}
}

Finally, restart nginx. successful:

/Opt/apps/nginx/sbin/nginx-s reload

The above describes how to configure https for nginx, including some content, and hope to help those who are interested in the PHP Tutorial.

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.