![](/img/trans.png)
[英]Issue with Deploying Vue.js + Node + MySQL + NginX app @DigitalOcean
[英]Deploying a laravel app with a node js app in nginx
我有一个使用pm2运行的node.js应用程序。 当我到达终点时,我看到了东西。 但是,当我尝试执行连接到laravel的后端api的操作时,什么也没发生。
这是我配置Nginx配置的方式:
server {
listen 80;
server_name make.tube;
root /maketube/api/public;
# This is the "last resort" nginx will direct to when no other matches with location have been found.
# This will proxy pass to another website (should be tested with http://localhost:3000 in your case).
location / {
proxy_pass http://localhost:3000;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
}
# All requests that start with /api are directed to the laravel location.
# It will only look for a file named index.html
location /api {
index index.html;
}
}
当我尝试执行应连接到后端的操作(例如登录)时,它无法正常工作,请尝试在make.tube( http:// localhost:3000 / api / auth / login / )上登录功能 。
有谁知道我该如何工作,以便在我执行登录操作时将其连接到我的laravel后端?
通过在本地环境中玩耍,我想到了以下简化版本:
server {
listen 80;
server_name test.test;
root /home/vagrant/test;
# This is the "last resort" nginx will direct to when no other matches with location have been found.
# This will proxy pass to another website (should be tested with http://localhost:3000 in your case).
location / {
proxy_pass http://node.test/;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
}
# All requests that start with /api are directed to the laravel location.
# It will only look for a file named index.html
location /api {
index index.html;
}
}
我设法proxy_pass
像一个请求http://test.test
到另一个网站http://node.test
“我是节点”,这显示正确的内容 同样所有以/api
开头的请求(例如http://test.test/api
/home/vagrant/test/api/index.html
都指向/home/vagrant/test/api/index.html
中显示“我是api”的文件。
在对54775192的回答中,我确实在位置块中犯了一个错误。 下列:
location /api {
root /location/of/laravel;
index index.php;
}
将导致错误,nginx尝试获取名为/location/of/laravel/api
,该文件不存在,而不是预期的/location/of/laravel/api/index.php
。
不知道为什么在这一刻。
这就是Nginx的工作方式。 我们可以使用别名来防止这种情况的发生。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.