Nginx代理和nuxtjs未连接

时间:2019-10-31 08:09:31

标签: nginx centos nuxt.js

我安装了nginx和nuxtjs,但仅在浏览器私有模式下加载了

nuxtjs在端口8081上运行

这是我的配置:

server {
        listen       8080 default_server;
        listen       localhost:8080 default_server;
        server_name  _;

        location / {
                proxy_pass http://localhost:8081;
                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;
        }

1 个答案:

答案 0 :(得分:2)

如果您的Nuxtjs是8081端口上的负载,则您的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     your-domain;    # 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://localhost:8081; # set the address of the Node.js instance here
    }
}

有关更多信息,请访问官方文档: https://nuxtjs.org/faq/nginx-proxy/