【问题标题】:How to deploy laravel backend with nginx?如何使用 nginx 部署 laravel 后端?
【发布时间】:2018-10-11 06:54:40
【问题描述】:

我有一个 spa 项目,前端和后端运行在不同的端口。

我使用 laravel 搭建后端,完成项目后我运行命令启动。

php artisan serve --port=3001 

而 nginx 是这样的:

# backend
server {
        listen 3000 default_server;
        listen [::]:3000 default_server;

        root /usr/nextJs/nextTestBackend/public;

        index index.php index.html index.htm index.nginx-debian.html;

        server_name _;

        location / {
                proxy_pass http://localhost:3001;

                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;
        }
}

之后,127.0.0.1:3000/api/GET/users 会变成 127.0.0.1:3001/api/GET/users 然后访问我的 laravel 后端.

这是用 nginx 部署后端的好方法吗?还是有其他方法可以做到?

我想知道在生产中使用 php artisan serve 是否可以?

【问题讨论】:

标签: laravel nginx


【解决方案1】:

这是用 nginx 部署后端的好方法吗?是的,nginx是不错的选择 这是你的好导师https://www.digitalocean.com/community/tutorials/how-to-deploy-a-laravel-application-with-nginx-on-ubuntu-16-04 或者还有其他方法可以做到吗?你可以使用apache

【讨论】:

  • 在生产环境中使用 php artisan serve 可以吗?
  • @jimmy 不!为此使用 php-fpm;查看 serversforhackers.com 网站,那里的人解释了一切。
猜你喜欢
  • 2021-09-07
  • 2018-03-20
  • 2021-11-11
  • 1970-01-01
  • 2019-09-07
  • 2020-06-14
  • 1970-01-01
  • 2021-01-30
  • 2011-07-17
相关资源
最近更新 更多