1.简介
当您准备将Laravel应用程序部署到生产环境时,可以做一些重要的事情来确保您的应用程序尽可能高效地运行。
在本文档中,我们将介绍一些确保您的Laravel应用程序正确部署的良好起点。
2.服务器配置
2.1 Nginx
如果要将应用程序部署到运行Nginx的服务器,则可以使用以下配置文件作为配置Web服务器的起点。
最有可能的是,将需要根据服务器的配置自定义此文件。
如果您希望在管理服务器方面获得帮助,请考虑使用诸如Laravel Forge之类的服务:
server {
listen 80;
server_name example.com;
root /srv/example.com/public;
add_header X-Frame-Options "SAMEORIGIN";
add_header X-XSS-Protection "1; mode=block";
add_header X-Content-Type-Options "nosniff";
index 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