本篇文章给大家带来的内容是关于laravel框架中nginx配置站点的详细讲解,有一定的参考价值,有需要的朋友可以参考一下,希望对你有所帮助。
前言
设置laravel项目的域名站点的时候,需要对nginx做一些对应的重写rewrite配置,用来做相关路由,否则会报404。
nginx.conf配置
server { listen 80; server_name xxx.com; #域名 root /data/www/myProject/blog/public; #站点目录,请求到laravel项目的public目录 index index.html index.htm index.php; #默认请求的文件 location ~ .php$ { fastcgi_pass 127.0.0.1:9000; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; include fastcgi_params; } location / { try_files $uri $uri/ /index.php?$query_string; # 这一句是laravel部署必须的,将index.php隐藏掉 } if (!-d $request_filename) { rewrite ^/(.+)/$ /$1 permanent; } # 去除index action if ($request_uri ~* index/?$) { rewrite ^/(.*)/index/?$ /$1 permanent; } # 根据laravel规则进行url重写 if (!-e $request_filename) { rewrite ^/(.*)$ /index.php?/$1 last; break; } location = /50x.html { root html; }}
操作及实例
对nginx.conf重写站点后,要重启nginx:
sudo nginx -s reload
以laravel5.2版本为例,模拟输出hello world,可以在laravel项目中app/Http/routes.php中定义一个hello的路由:
造点AI
夸克 · 造点AI
325 查看详情
Route::get('/hello', function(){ return 'hello world'; });
浏览器输入xxx.com/hello即可在浏览器打印出hello world
相关推荐:
nginx下laravel框架rewrite的设置
Nginx中运行PHP框架Laravel的配置文件
以上就是laravel框架中nginx配置站点的详细讲解的详细内容,更多请关注php中文网其它相关文章!
版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。
如发现本站有涉嫌抄袭侵权/违法违规的内容, 请发送邮件至 chuangxiangniao@163.com 举报,一经查实,本站将立刻删除。
发布者:程序猿,转转请注明出处:https://www.chuangxiangniao.com/p/499558.html
微信扫一扫
支付宝扫一扫