前后端分离的前端代码是怎么部署到生产环境中的

1:用的是Nginx
2:前端有用到vue路由
2:所以在web目录里面要npm run vue吗?

阅读 10.1k
2 个回答

老哥,我看你问题标签里包含了laravel,那么后端应该 laravel
首先,若前端代码都完成,可以打包放置在laravel项目 /public 目录下。
前端路由需要 nginx 的配置,比如:

location / {
            root /var/www/xxxx/public/dist;
            index index.html index.htm;
            try_files $uri $uri/ /index.html;
}

因为你的项目是前后端分离,因而后端api路由,可以反向代理一下:

server {
    listen 80;
    ....
    location /api {
            proxy_set_header Host $http_host;
            proxy_pass http://backend;
    }
}

  ......

upstream backend {
        server 127.0.0.1:8080;
}
server {
        listen 8080;
        server_name localhost;
        root /var/www/xxxx/public;
        index index.php;
        location / {
                try_files $uri $uri/ /index.php?$query_string;
        }
        
        location ~ \.php$ {
                try_files $uri /index.php=404;
                fastcgi_split_path_info ^(.+\.php)(/.+)$;
                fastcgi_pass unix:/var/run/php7.1-fpm.sock;
                fastcgi_index index.php;
                fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
                include fastcgi_params;
        }
}

输出打包以后的HTML,js,css啊

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题