如何在HTTPS中运行Nuxt项目?

时间:2019-05-13 06:27:48

标签: nginx https nuxt.js nuxt

我设法将nginx转换为https。当我更改其配置以支持nuxt项目的运行时。然后只是nginx没有打开该网站。

我怀疑是因为我的nuxt项目无法在https中工作。那么如何在https中运行nuxt。

我做了什么: 我重新安装了使用letencrypt bot安装证书的nginx。然后我检查了nginx是否成为https。 然后我在npm run start中运行了nuxt。然后更改了nginx的配置以支持运行nuxt。 然后页面不再可见。

更新1: 我已经卸载了nginx。 我在生产模式下启动了nuxt。 我根据获得代理更改了nginx。

map $sent_http_content_type $expires {
    "text/html"                 epoch;
    "text/html; charset=utf-8"  epoch;
    default                     off;
}

server {
    listen          80;             # the port nginx is listening on
    server_name     example.me wwww.example.me;    # setup your domain here


    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; # set the adress of the Node.js instance here
    }

    listen 443 ssl; # managed by Certbot
    ssl_certificate /etc/letsencrypt/live/example.me-0001/fullchain.pem; # managed by Certbot
    ssl_certificate_key /etc/letsencrypt/live/example.me-0001/privkey.pem; # managed by Certbot
    include /etc/letsencrypt/options-ssl-nginx.conf; # managed by Certbot
    ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem; # managed by Certbot

}

现在由于某种原因它可以工作。.在证书安装之前,我已经安装了这些证书,也许这些证书没有卸载。实际上很难理解它是如何开始工作的。

但是现在它也允许使用http。我想将所有http都定向到https,但是当我输入

map $sent_http_content_type $expires {
    "text/html"                 epoch;
    "text/html; charset=utf-8"  epoch;
    default                     off;
}

server {
    listen          80;             # the port nginx is listening on
    server_name     example.me wwww.example.me;    # setup your domain here
    return 301 https://$host$request_uri;

    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; # set the adress of the Node.js instance here
    }

    listen 443 ssl; # managed by Certbot
    ssl_certificate /etc/letsencrypt/live/example.me-0001/fullchain.pem; # managed by Certbot
    ssl_certificate_key /etc/letsencrypt/live/example.me-0001/privkey.pem; # managed by Certbot
    include /etc/letsencrypt/options-ssl-nginx.conf; # managed by Certbot
    ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem; # managed by Certbot

}

返回301 https:// $ host $ request_uri;导致一切崩溃

现在,新问题正在从https Web服务中调用。但是对于这个主题,它是封闭的。

0 个答案:

没有答案