Add https support to the site

Source: Internet
Author: User
: This article describes how to add https support to the website. For more information about PHP tutorials, see. Reference from

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

Https is an encryption protocol for http. it ensures that the communication data is encrypted when users access the website. This prevents third-party listening and protects user privacy. Here we will summarize how to add https support to Rails.

First, assume that your rails is running. Http://yourserver.comThe server is ubuntu, and the local access method is 127.0.0.1: 8787, Then you need to use NginxTo provide https services.

First install NginxAnd Openssl:

            
             sudo apt-get install nginx openssl
            
Generate the server's public key:

                
                 openssl req -new -nodes -keyout server.key -out server.csropenssl x509 -req -days 365 -in server.csr -signkey server.key -out server.crt
                
Several generated files:

  • Server. keyThe private key of the server.
  • Server. csr(Certificate signing request) https certificate signature request.
  • Server. crtThe generated server certificate.
  • Then we can configure the nginx service with these files.

    Generate the nginx configuration file:

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

    Content:

    12345678910111213141516171819202122232425
                           
                            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;  }}
                           

    The Server_name, yourpath.

    Then restart nginx:

                       
                        sudo service nginx restart
                       

    If no error is reported, you can use Https://yourserver.comTo access your website.

    However, the browser will block your continued access or you need to confirm. The browser will save a list of trusted websites. your server encryption is generated by yourself, not in it. If your website is commercially available, you 'd better register it. Here is a guide.

    References:

    • Railscast

    Posted by mechanical materialism Mar 24th, 2013 rails


    The above describes how to add https support to the site, including content, and hope to be helpful to friends who are interested in PHP tutorials.

    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.