首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >在同一台nginx服务器上的Nuxt.js前端和laravel api数字海洋

在同一台nginx服务器上的Nuxt.js前端和laravel api数字海洋
EN

Stack Overflow用户
提问于 2020-12-19 19:27:18
回答 1查看 378关注 0票数 3

我有一个用于前端的nuxt应用程序SPA和一个laravel API。Nuxt调用API请求。我试图将它部署在一个数字海洋水滴中,但我遇到了问题。我的laravel应用程序似乎可以正常工作,但我无法让nuxt显示我的设置

Ubuntu 20 nginx 1.18 php 7.4

laravel nginx服务器块

代码语言:javascript
复制
server {
    listen 80;
    server_name DROPLET_IP;
    root /var/www/laravel-api/public;

    add_header X-Frame-Options "SAMEORIGIN";
    add_header X-XSS-Protection "1; mode=block";
    add_header X-Content-Type-Options "nosniff";

    index index.html index.htm index.php;

    charset utf-8;

    location / {
        try_files $uri $uri/ /index.php?$query_string;
    }

    location = /favicon.ico { access_log off; log_not_found off; }
    location = /robots.txt  { access_log off; log_not_found off; }

    error_page 404 /index.php;

    location ~ \.php$ {
        fastcgi_pass unix:/var/run/php/php7.4-fpm.sock;
        fastcgi_index index.php;
        fastcgi_param SCRIPT_FILENAME $realpath_root$fastcgi_script_name;
        include fastcgi_params;
    }

    location ~ /\.(?!well-known).* {
        deny all;
    }

}

这是我的nuxt服务器块:

代码语言:javascript
复制
server {
    listen 3000;
    server_name DROPLET_IP;
    keepalive_timeout 60;
    index index.html;

    location / {
        root /var/www/nuxt-front/dist;

    }
}

这两个都在他们自己的站点中-可用并启用指向站点的符号链接。

由于某些原因,当我访问http://DROPLET_IP:3000时。它就挂起来了。

有没有一种特殊的方式可以让我按预期运行呢?

EN

回答 1

Stack Overflow用户

发布于 2021-02-22 18:43:49

使用root

代码语言:javascript
复制
server {
    listen 80;
    server_name example.com;
    keepalive_timeout 60;
    root /var/www/nuxt-front/dist;    
  
}

使用代理传递

代码语言:javascript
复制
server {
    listen 80;
    server_name example.com;
    location / {
        proxy_pass http://127.0.0.1:3000;
        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;
    }
}
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/65369328

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档