部署Laravel和React spa [英] Deploy Laravel and React spa
问题描述
如何将这两个部署在一起,我不喜欢Laravel React预设,我想将两者分开,捆绑React应用程序并将它们与任何Web服务器(apache,nginx ...)一起部署
How can I deploy these two together, I don't like the Laravel React preset, I want to separate both, bundle the React app and deploy them together with any web server (apache, nginx...)
编辑
这是我的Laravel配置,但未加载路由
This is my config for Laravel, but it isn't loading the routes
server {
listen 8000;
server_name 127.0.0.1
root "..\..\Proyecto\Backend\JWT\public";
add_header 'Access-Control-Allow-Origin' '*';
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 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $realpath_root$fastcgi_script_name;
include fastcgi_params;
}
location ~ /\.(?!well-known).* {
deny all;
}
}
推荐答案
您可以使用nginx单独运行它们
You can run them separately using nginx
您分别在单独的端口上运行,并使用方法(POST/GET)推送/获取数据
you run each on separate ports and use methods (POST/GET) to push/get data
使用pm2( http://pm2.keymetrics.io/)运行React(我建议因为您可以监视react应用的活动,并且如果要进行维护,则可以停止当前应用进程并运行维护中"的应用进程)
use pm2 (http://pm2.keymetrics.io/) for running React (I recommend it because you can monitor the activity of the react app and if you want to do maintenance you can stop the current app process and run a "under maintenance" app process)
您可以在此处阅读有关在Nginx上运行laravel的更多信息(
you can read more about running laravel on nginx here (https://www.digitalocean.com/community/tutorials/how-to-deploy-a-laravel-application-with-nginx-on-ubuntu-16-04)
对于在没有pm2的情况下运行react的情况,您必须构建项目yarn build
,并告诉nginx您要加载的文件是构建文件内部的index.html
as for running react without pm2, you have to build the project yarn build
and tell nginx that the file you want to load is the index.html
inside of the build file
假设您使用的是ubuntu服务器,并且已将代码上传到github或gitlab
assuming that you are using an ubuntu server and you uploaded your code to github or gitlab
server {
listen 50;
root /var/www/[Your repo name]/build;
server_name [your.domain.com] [your other domain if you want to];
index index.html;
location / {
try_files $uri /index.html;
}
}
您可以将此代码与laravel配置一起写在nginx配置内部
you write this inside of your nginx configuration along with the laravel configuration on a separate port
希望我的回答有所帮助
这篇关于部署Laravel和React spa的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!