Enable HSTS and apply for HSTS Preload List
in Tutorial with 32 comments
Enable HSTS and apply for HSTS Preload List
in Tutorial with 32 comments

HSTS is the abbreviation of "HTTP Strict Transport Security" (HTTP Strict Transport Security). After this setting is enabled, mainstream browsers will forcibly use HTTPS to request resources, which can more effectively protect the data security of your website and users. In general (HSTS is not enabled), the browser will allow users to continue to use insecure connections to access after they understand the security risks. However, if HSTS is enabled, this is not allowed. Therefore, you must plan to use HTTPS for a long time before starting HSTS.

First, our website linpx.com joined Chrome's HSTS Preload List In Chromium transport_security_state_static.json Can be viewed in

Enable HSTS

HSTS is a response header in the following format:

 Strict-Transport-Security: max-age=31536000;  includeSubDomains;  preload;

The HSTS response header can only be used for HTTPS responses; The website must use the default 443 port; Domain name must be used, not IP. After HSTS is enabled, users cannot choose to ignore the site certificate once it is wrong.


Here is a simple tutorial for Nginx to start HSTS

Open the Nginx conf configuration file corresponding to the website

Suppose my configuration file is in the directory of/usr/local/nginx/conf/vhost

 vim /usr/local/nginx/conf/vhost/www.linpx.com.conf

join

 server { ··· add_header Strict-Transport-Security "max-age=31536000; includeSubdomains; preload"; ···

Apply for Preload List

HSTS will not take effect until the browser has visited your website once. If you want to take effect in advance, you need to apply for HSTS Preloading List.

At present, the Preload List is maintained by Google Chrome, which is used by Chrome, Firefox, Safari, IE 11 and Microsoft Edge. If you want to add your domain name to this list, you must first meet the following conditions:

Go when you feel comfortable HSTS Preload List (hstspreload.appspot.com) This page applies.

Enter your website in the only text box. This list is reviewed manually, so it may take a while

 3123123.png

This is the effect of successfully joining the HSTS website

 318752.png

Special Reminder : For HSTS and HSTS Preload List, if you cannot ensure that HTTPS services are always provided, do not enable them. Because once HSTS takes effect, if you want to redirect the website to HTTP, old users will be redirected indefinitely. The only way is to change the domain name.

That's about it. This article is based on the previous article( Optimization of Nginx's SSL configuration )Supplement to.

At the same time, because I have read QuQu's articles many times, and I am familiar with and agree with what he said, this article refers to many parts: imququ.com/post/sth-about-switch-to-https.htm

Responses
  1. I applied before. But I think it's too troublesome, and now I have canceled 2333

    Reply
  2. Smile on Daming Mountain

    Hello, blogger, please let me ask you to 301 websites with and without w to https without w
    How to write this rule? I tried several times but failed https://hstspreload.appspot.com/ Detection of,
    It is said that http should not be marked with hsts. It is obviously that it is not detected that http is transferred to https

    Reply
    1. @Smile on Daming Mountain

      You idiot... I commented here. Why didn't I pass? Please ask me first.
      As long as the rules are written correctly, don't open the CDN, just record the A directly, because you can't detect 80 ports

      Reply
    2. @Smile on Daming Mountain

      You can add a server {} to the configuration file of your site, as follows
      server {
      listen 80;
      server_name www.linpx.com;
      rewrite ^/(.*) https://$server_name/$1 permanent;
      }

      Reply
      1. Smile on Daming Mountain
        @Chakhsu Lau

        Thanks for your reply. I'll try another one
        if ($host = http://www.xxx.com ) { return 301 $ scheme://xxx.com $request_uri; }

        This can not.. I was surprised that several writing methods were changed, and hsts detected my errors...
        I want to know why there are no 80 but 443 bloggers in your server
        Why don't I have my picture..

        Reply
        1. @Smile on Daming Mountain

          If you have 80, you can remove it. Different configurations are OK.

          Reply
          1. Smile on Daming Mountain
            @Chakhsu

            Well, I forgot to mention that my local redirects are effective, but when I submit the hsts, I always remind me that http has not been redirected to https

            Reply
          2. Smile on Daming Mountain
            @Chakhsu

            Well, actually, I've tried all the bloggers.. Still unsuccessful.. What about that. Is it convenient for you? QQ sends your documents to see? thank you

            My QQ 5795516

            Reply
            1. @Smile on Daming Mountain

              The avatar didn't show up because you didn't go https://en.gravatar.com/ set up

              Reply
            2. @Smile on Daming Mountain

              You need to restart nginx after modification

              Reply
              1. Smile on Daming Mountain
                @Chakhsu

                Of course, it's restarted. I've been depressed since the change. I've tried all kinds of rules
                Establish two servers, one 80 and one 443
                The definition of 80 turns to 443
                Is this idea wrong? Is it wrong... I'm smoking, man/ Funny....

                Reply
            3. @Smile on Daming Mountain

              Are you sure you want to remind http not to switch to https?

              Reply
              1. Zen Cat
                @Chakhsu

                Big Brother. The goods that brush your comments downstairs are my friends, but actually my aunt and brother are studying. i 'm sorry

                Reply
              2. Smile on Daming Mountain
                @Chakhsu

                We've done it. We've done the right thing for bloggers. Normally, it's configured like this, but we have to write rules according to our own environment. The second reason is the damned cdn
                。。。。

                Reply
              3. Smile on Daming Mountain
                @Chakhsu

                Warning: unnecessary HSTS header over HTTP

                This means not to add the hsts tag on Http. It is obvious that the problem of Error: No redirect from HTTP

                Reply
              4. Smile on Daming Mountain
                @Chakhsu

                Very sure... Not only that I didn't go to https, but also that I didn't have an hsts ID.. I went
                Error: No redirect from HTTP

                Warning: Unnecessary HSTS header over HTTP

                Just these two goods.. I have been depressed for a long time,
                I wonder if this is the problem of CDN? But it's all empty

                Reply
  3. I went to test again, and this will prompt
    The HTTP page, this hsts, is boring about http. I'm doing 301http to https now

    Reply
    1. @Zen Cat

      The reason for the question that the http page should not be marked with the hsts tag is finally found. The reason is that the previous switch from http to https was 301, and the 80 port http protocol was still exposed, so it will be detected. The solution is to switch to port 80 in the server or use DNS to switch to https. I didn't notice this problem for a day

      Reply
  4. Zen Cat

    Big Brother.. I enabled http2 and added HSTS response headers. Why can I detect or prompt warning: unnecessary HSTS header over HTTP
    The HTTP page at http://chancat.photo sends an HSTS header. This has no effect over HTTP, and should be removed.

    Reply
    1. @Zen Cat

      Give me a link

      Reply
      1. Zen Cat
        @Chakhsu

        by the way.. Could it be the reason why I wrote hsts in location? In fact, I don't know why many things in my environment can be used in the location, but not in the server.. Is the cache problem? I opened the Ngx cache purge module..
        The environment is lnmp, debian7.3x64

        Reply
        1. @Zen Cat

          I don't know

          Reply
          1. Zen Cat
            @Chakhsu

            Sure enough, I just changed to the server again. I went to check it and prompted that I didn't have the HSTS ID 666

            Reply
      2. Zen Cat
        @Chakhsu

        What's in the tip below the forehead
        chancat.photo
        In addition, if you find your theme, just click reply under the tablet

        Reply
        1. @Zen Cat

          I'll see later. I'm cooking

          Reply
          1. Zen Cat
            @Chakhsu

            Hey, this family man 233

            Reply
  5. I think it's unnecessary. Just redirect 301 directly to https

    Reply
    1. @The Great Devil of the Garden

      301 redirection can solve most problems, such as hijacking by operators;
      However, it cannot resist malicious attacks.

      Reply
    2. @The Great Devil of the Garden

      Are you happy to shake hands many times?

      Reply
    3. @The Great Devil of the Garden

      This is obvious, but enabling HSTS can solve the HTTPS downgrade attack well, and joining HSTS Preload List can prevent the first HTTP request from being hijacked. That's about it.

      Reply
  6. HTTPS is the future. And now.

    Reply