Linux nginx 配置HTTPS

  server {
        listen 80;
        server_name xxxxx; #需要将xxxxx替换成证书绑定的域名。
        rewrite ^(.*)$ https://$host$1; #将所有HTTP请求通过rewrite指令重定向到HTTPS。
    }
    
     server {
        listen 443 ssl;
        server_name xxxxx;#需要将xxxxx替换成证书绑定的域名。
        ssl_certificate   /xxxxx/xxx.pem;
        ssl_certificate_key  /xxxx/xxxx.key;
        ssl_session_timeout 5m;
        ssl_ciphers ECDHE-RSA-AES128-GCM-SHA256:ECDHE:ECDH:AES:HIGH:!NULL:!aNULL:!MD5:!ADH:!RC4;
        ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
        ssl_prefer_server_ciphers on;
        #前段请求地址
        location / {
                root /html;#Web网站程序存放目录
                index index.html index.htm;
                 try_files $uri $uri/ /index.html; #解决页面刷新404问题
                 proxy_set_header Host $host;
                 proxy_set_header X-Real-IP $remote_addr;
                 proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        }
        # 请求后台
        location /api{
                  proxy_set_header Host $http_host;
                  proxy_set_header X-Real-IP $remote_addr;
                  proxy_set_header REMOTE-HOST $remote_addr;
                  proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
                  proxy_pass http://localhost:8080;
                  
        }
        
    }

你可能感兴趣的:(Linux nginx 配置HTTPS)