Implement the nginx configuration problem of https website

I follow Penguin"s code to implement nginx configuration (parameters have been modified and can be accessed)
now there are several problems:
1. What is the first upstream?
2. I now jump to https, every time I visit http, even if I delete rewrite, how to separate
3. How to hang a static website under the https domain name? I tried to set root root/myweb; to return

upstream app_weapp {
    server localhost:5757;
    keepalive 8;
}

server {
    listen      80;
    server_name wx.ijason.cc;

    rewrite ^(.*)$ https://$server_name$1 permanent;
}

server {
    listen      443;
    server_name wx.ijason.cc;

    ssl on;

    ssl_certificate           /data/release/nginx/1_wx.ijason.cc_bundle.crt;
    ssl_certificate_key       /data/release/nginx/2_wx.ijason.cc.key;
    ssl_session_timeout       5m;
    ssl_protocols             TLSv1 TLSv1.1 TLSv1.2;
    ssl_ciphers               ECDHE-RSA-AES256-GCM-SHA384:ECDHE-RSA-AES128-GCM-SHA256:DHE-RSA-AES256-GCM-SHA384:ECDHE-RSA-AES256-SHA384:ECDHE-RSA-AES128-SHA256:ECDHE-RSA-AES256-SHA:ECDHE-RSA-AES128-SHA:DHE-RSA-AES256-SHA:DHE-RSA-AES128-SHA;
    ssl_session_cache         shared:SSL:50m;
    ssl_prefer_server_ciphers on;

    location / {
        proxy_pass http://app_weapp;
        proxy_http_version 1.1;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection "upgrade";
        proxy_set_header Host $host;
        proxy_cache_bypass $http_upgrade;
    }
}
May.27,2021

  1. upstream you can regard it as load balancer , for example, you have made the following configuration

    upstream app_weapp {
        server localhost:5757;
        server localhost:5758;
    }

    then the requests you receive will be diverted to these two applications, of course, if you deploy the same application to two servers, such as

    upstream app_weapp {
        server 192.168.2.1:5757;
        server 192.168.2.2:5757;
    }

    then your traffic will be diverted to these two servers, along with the following proxy_pass , and some load balancing algorithms. For more information, please see document: Using nginx as HTTP load balancer .

  2. visit http to force a jump to https it is true that rewrite is working, probably because you haven't reloaded the configuration after you changed it: nginx-s reload
  3. if it is a static page, you can delete location /. a whole piece of code directly, or upstream , and then replace the whole block with root . If you must use upsteam , then your static page must be deployed where localhost:5757 can access

    .
    • solution 1: discard upsteam directly, and mount resources under https

      .
      server {
          listen      443;
          server_name wx.ijason.cc;
          root root/myweb;
          ssl on;
      
          ssl_certificate           /data/release/nginx/1_wx.ijason.cc_bundle.crt;
          ssl_certificate_key       /data/release/nginx/2_wx.ijason.cc.key;
          ssl_session_timeout       5m;
          ssl_protocols             TLSv1 TLSv1.1 TLSv1.2;
          ssl_ciphers               ECDHE-RSA-AES256-GCM-SHA384:ECDHE-RSA-AES128-GCM-SHA256:DHE-RSA-AES256-GCM-SHA384:ECDHE-RSA-AES256-SHA384:ECDHE-RSA-AES128-SHA256:ECDHE-RSA-AES256-SHA:ECDHE-RSA-AES128-SHA:DHE-RSA-AES256-SHA:DHE-RSA-AES128-SHA;
          ssl_session_cache         shared:SSL:50m;
          ssl_prefer_server_ciphers on;
          
      }
    • solution 2: keep upsteam and add the following configuration. The following configuration adds another application, which can be accessed through localhost:5757 . With https and upstream above, the traffic accessing https can be forwarded here

      .
      server {
          listen  5757;
          root root/myweb;
          index index.html;
      }
Menu