laravel - Nuxt.js 前端和 laravel api 在同一个 nginx 服务器上 数字海洋
问题描述
我有一个用于前端的 nuxt 应用程序 SPA 和一个 laravel API。Nuxt 调用 API 请求。我正在尝试将其部署在一个数字海滴中,但我遇到了问题。我的 laravel 应用程序似乎正在运行,但我无法让 nuxt 显示这里是我的设置
Ubuntu 20 nginx 1.18 php 7.4
laravel nginx 服务器块
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 服务器块:
server {
listen 3000;
server_name DROPLET_IP;
keepalive_timeout 60;
index index.html;
location / {
root /var/www/nuxt-front/dist;
}
}
这两个都在它们自己的站点中可用,并且启用站点的符号链接。
出于某种原因,当我访问http://DROPLET_IP:3000
. 它只是挂起。
有没有一种特殊的方式我应该这样做才能按预期运行?
解决方案
使用根
server {
listen 80;
server_name example.com;
keepalive_timeout 60;
root /var/www/nuxt-front/dist;
}
或者
使用代理通行证
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;
}
}
推荐阅读
- javascript - JavaScript 的奥秘似乎没有人能够弄清楚 - 复制到剪贴板并不总是在相同的值上工作。没有错误
- java - 使用 spring @Query 获取节点和关系列表
- c# - 使用 .Net Framework 生成 SAML2 Idp 元数据
- asp.net-mvc - 如何在用户会话中更改 MVC 网站的默认登录 URL?
- javascript - 如何在另一个实体上创建或更新一个实体已创建
- java - Zebra 打印机 GX420D 重启后不使用 Windows 设置,直到从 Windows 打印测试页
- excel - 错误“未定义用户定义的类型”保持弹出?
- javascript - 使用反应钩子将所选项目显示到另一个组件
- sql - 在 Oracle Apex 中单击按钮时显示 APEX$ROW_ACTION
- apache-kafka - Kafka - 当前 ISR Set(1) 的大小不足以满足分区 __consumer_offsets-0 的 min.isr 要求 2