简体   繁体   English

强制 http 重定向到 https nginx + Z9FDF1EFEE91FF580B192FA2C3325920B

[英]force http redirect to https nginx + Nuxt.js

I am deploying an application made with nuxt.js, as hosting I am using digitalocean + serverpilot.我正在部署一个使用 nuxt.js 制作的应用程序,因为我使用的是 digitalocean + serverpilot。

I'm having trouble not to enable SSL but to force redirection from HTTP to HTTPS我无法启用 SSL 而是强制从 HTTP 重定向到 HTTPS

below is the nginx setting I'm using下面是我正在使用的 nginx 设置

map $sent_http_content_type $expires {
    "text/html"                 epoch;
    "text/html; charset=utf-8"  epoch;
    default                     off;
}
server {
    listen 80;
    server_name            admin.domain.com;

    gzip            on;
    gzip_types      text/plain application/xml text/css application/javascript;
    gzip_min_length 1000;

    location / {
        expires $expires;
        proxy_redirect                      off;
        proxy_set_header Host               $host;
        proxy_set_header X-Real-IP          $remote_addr;
        proxy_set_header X-Forwarded-For    $proxy_add_x_forwarded_for;
        proxy_set_header X-Forwarded-Proto  $scheme;
        proxy_read_timeout          1m;
        proxy_connect_timeout       1m;
        proxy_pass                          http://127.0.0.1:3000;
    }
}
server {
    listen    443 ssl default_server;
    listen    [::]:443 ssl default_server;
    ssl_certificate_key    ssl/_default.key;
    ssl_certificate        ssl/_default.crt;
    return    444;
}

if i turn on https://admin.domain.com it works如果我打开https://admin.domain.com它可以工作

if I go to http://admin.domain.com it does not redirect to https and i get unsecured warning如果我 go 到unsecured http://admin.domain.com它不会重定向到https警告

NOTE: I would like to configure inside the server block because in future I will have other servers, for example blog.domain.com注意:我想在server块内进行配置,因为将来我会有其他服务器,例如blog.domain.com

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM