Add HTTPS support to the site

Source: Internet
Author: User
Tags php tutorial
This article refers to self

http://blog.linjunhalida.com/blog/using-https-for-rails/

HTTPS is an encryption protocol for HTTP, it can guarantee the user to visit the process of the website, communication data is encrypted, so as to prevent third-party monitoring, protect user privacy. Here's a summary of how to add HTTPS support to rails.

First, let's say your rails is running, Http://yourserver.com, the server is Ubuntu, and the local access method is 127.0.0.1:8787, then you need to use NginxTo provide HTTPS services.

Install first NginxAnd Openssl:

 
             
              
  sudo apt-get install nginx OpenSSL
 
             
Generate the secret key of the server:

 
                 
                  
  OpenSSL req-new-nodes-keyout server.key-out server.csropenssl x509-req-days 365-in server.csr-signkey Server.key- Out SERVER.CRT
 
                 
Several files are generated to explain:

  • Server.key the private key of the server.
  • SERVER.CSR (certificate signing request) HTTPS certificate signing requests.
  • SERVER.CRT the generated server certificate.
  • Then with these files, we can configure the Nginx service.

    To generate Nginx configuration files:

     
                       
                        
      sudo touch/etc/nginx/sites-available/yourserversudo ln-s/etc/nginx/sites-available/yourserver/etc/nginx/ Sites-enabledsudo Vi/etc/nginx/sites-available/yourserver
     
                       

    What's Inside:

    1 2 3 4 5 6 7 8 9 Ten  One  A  -  -  the  -  -  -  +  -  +  A  at  -  -
                          
                            upstream Unicorn {  server 127.0.0.1:8787 fail_timeout=0; }server {  listen 443; server_name yourserver.com;  SSL on; ssl_certificate yourpath/server.crt; Ssl_certificate_key Yourpath/server.key;  ssl_session_timeout 5m;  ssl_protocols SSLv2 SSLv3 TLSv1; ssl_ciphers high:!anull:! MD5; ssl_prefer_server_ciphers on;  Location /{  proxy_set_header Host $host; proxy_set_header x-forwarded-for $proxy _add_x_forwarded_for; Proxy_set_header X-forwarded-proto https; proxy_redirect off; Proxy_pass Http://localserver;   }}
                          

    Need to modify the inside Server_name,yourpath.

    Then reboot the Nginx:

     
                       
                        
      sudo service nginx restart
     
                       

    If there is no error, then you can visit your website via https://yourserver.com.

    However, the browser will prevent you from continuing your visit or need your confirmation. The browser saves a list of trusted websites, and your server encryption is generated by itself, not inside. If your website is commercial, it's best to register it. Here's a guide.

    Citation information:

      • Railscast

    Posted by Mechanical materialism Marth, rails


    The above is introduced to the site with HTTPS support, including the aspects of the content, I hope that the PHP tutorial interested in a friend helpful.

  • Related Article

    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.