laravel 上线部署最佳实践

nginx  配置  

listen 80 default_server;
server_name xxxx;
index index.php index.html;    优先 index.php
root /home/wwwroot/xxx/public/;
add_header X-Frame-Options "SAMEORIGIN";  不要用frame 
add_header X-XSS-Protection "1; mode=block";   启动 xss 过滤
add_header X-Content-Type-Options "nosniff";    不要猜测  文件类型  返回是什么就是什么 
location = /favicon.ico { access_log off; log_not_found off; }   不要记录
location = /robots.txt { access_log off; log_not_found off; } 不要记录

include none.conf;
#error_page 404 /404.html;
location ~* ^/(css|img|js|flv|swf|download)/(.+)$ {   静态文件 直接下载 返回
}

include enable-php.conf;
location / {    先访问  $uri   然后 $uri/   然后 /index.php?$query_string
try_files $uri $uri/ /index.php?$query_string;
}
location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)$   缓存265天
{
expires 365d;
}

location ~* ^.+\.(jpg|jpeg|gif|png|bmp|css|js|swf|txt)$ { 不要记录
access_log off;
break;
}
location ~ .*\.(js|css)?$  缓存12小时
{
expires 12h;
}

location ~ /\.    屏蔽.
{
deny all;
}

 

权限   

一般要求文件拥有者不能是 nginx php 执行用户  但实际上你权限设置好无所谓的   

chown -R  www:www  wwwroot

chmod  -R 550 wwwroot   

find wwwroot -type f exec chmod 440 {}   除了storage  文件全部只给读  

chmod  -R 770 wwwroot/storage   这里是肯定要给770 的  但伪黑客  做不了手脚

 

修改 php配置文件  fastcgi.conf 

添加  fastcgi_param APP_ENV online;    自动切换配置用  增加文件  .env.online

 

部署代码

composer  install   安装依赖

php artisan down   网站先下线
git pull  
php artisan config:cache
php artisan optimize
php artisan migrate
php artisan up

 

posted @ 2018-02-13 16:23  ken桑带你飞  阅读(1168)  评论(0编辑  收藏  举报