【发布时间】:2019-02-11 16:26:07
【问题描述】:
所以我的服务器上有一个包含 2 个目录的 Web 应用程序项目: 1)前端 - 我从 pm2 开始的 nodejs 应用程序(next.js)。 2) api - laravel 后端 api
我也安装了 nginx 并尝试将此作为我的服务器设置:
server {
location / {
proxy_pass http://localhost: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;
}
listen 80;
listen [::]:80;
root /project/api/public;
index index.php index.html index.htm;
location / {
try_files $uri/ /index.php?$query_string;
}
location ~ \.php$ {
include snippets/fastcgi-php.conf;
fastcgi_pass unix:/var/run/php/php7.2-fpm.sock;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
}
}
现在,当我访问我的网址时,前端部分可以工作,所以当我访问 example.com 时,我会看到我的网络应用程序(因此端口 3000 的代理配置工作)。
无论后端/api 不起作用,我认为是因为当我执行后端任务时它不会重定向到 api。像 http://example.com:3000/api/auth/login/ 应该转到我的 laravel 应用程序。
"/api/..." 是后端端点。
我想我需要以某种方式定义一个位置 /api {} 才能转到 laravel 应用程序。
我们将不胜感激。
【问题讨论】: