网站首页 > 技术教程 正文
一个服务器不能配置多个子域名的时候很是尴尬,无法使用虚拟目录,只能通过二级目录访问。在根目录/data/wwwroot/default部署了多个laravel应用,laravel1,-laravel2...,然后按文档配置所谓的优雅链接,遇到了诸多问题:
- apache服务器:XAMPP的lamp环境
- nginx服务器:OneinStack自动部署lnmp环境
Apache服务器
在lamp环境下使用还是蛮简单,配置Laravel/public/.htaccess:
Options +FollowSymLinks RewriteEngine On RewriteCond %{REQUEST_FILENAME} !-d RewriteCond %{REQUEST_FILENAME} !-f RewriteRule ^ index.php [L]
即可,访问的地址:
http://test.comlaravel1/public/admin/index
http://test.com/laravel2/public/admin/index
nginx服务器
文档中说,只要在nginx.conf下配置:
location / { try_files $uri $uri/ /index.php?$query_string; }
即可,访问优雅链接,但结果有点失望,你会遇到问题:
- Access denied.
- No input file specified.
- 504
- ...
归根结底是nginx.conf配置问题,本人遇到最多就是Access denied,因为使用OneinStack自动部署lnmp环境,nginx.conf已经默认配置了,结果仔细对比,少了下面配置
fastcgi_split_path_info ^(.+\.php)(.*)$;
参考:https://segmentfault.com/a/1190000002667095
难怪laravel优雅链接index.php后面一直无法访问,目前为题已解决,附上一段网上的配置:
server { listen 80; server_name _; set $root_path '/data/www/default'; root $root_path; index index.php index.html index.htm; try_files $uri $uri/ @rewrite; location @rewrite { rewrite ^/(.*)$ /index.php?_url=/$1; } location ~ \.php { fastcgi_pass 127.0.0.1:9000; fastcgi_index /index.php; fastcgi_split_path_info ^(.+\.php)(/.+)$; fastcgi_param PATH_INFO $fastcgi_path_info; fastcgi_param PATH_TRANSLATED $document_root$fastcgi_path_info; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; include fastcgi_params; } location ~* ^/(css|img|js|flv|swf|download)/(.+)$ { root $root_path; } location ~ /\.ht { deny all; } }
http://test.com/laravel1/public/index.php/admin/index
http://test.com/laravel2/public/index.php/admin/index
都可以正常访问了,OK!
最后隐藏index.php
虽然上述配置在laravel中可以正常访问,但是一些放在public里面的静态资源可能无法访问,比如无法使用asset()函数时,路径中就包含index.php导致资源无法加载,所以建议隐藏index.php
if (!-e $request_filename) { rewrite ^/(.*)/public/(.*)$ /$1/public/index.php/$2 last; break; }
http://test.com/laravel1/public/admin/index
http://test.com/laravel2/public/admin/index
以上就无需加index.php,即可正常访问
猜你喜欢
- 2024-10-14 如何通过nginx反向代理来调试代码?
- 2024-10-14 云服务器部署1【Nginx、Supervisor、Flask、Python】
- 2024-10-14 利用ngrok或nginx公开内网服务到外网
- 2024-10-14 Nginx 配置 Https 免费证书访问(视频看不了是否配置了https证书)
- 2024-10-14 nginx反向代理配置去除前缀(nginx做反向代理后屏蔽url)
- 2024-10-14 经验分享:日活1万的wap页,每天稳定带来2000个激活
- 2024-10-14 nginx下关于配置https证书的流程(nginx配置文件详解)
- 2024-10-02 Nginx 配置 Https 免费证书访问(视频看不了是否配置了https证书)
- 2024-10-02 SEO必知:如何将顶级域名做301重定向到www二级域名
- 2024-10-02 Asp.Net项目的部署到Linux中(Linux + Jexus+Nginx)
你 发表评论:
欢迎- 最近发表
-
- 阿里P8大佬总结的Nacos入门笔记,从安装到进阶小白也能轻松学会
- Linux环境下,Jmeter压力测试的搭建及报错解决方法
- Java 在Word中合并单元格时删除重复值
- 解压缩软件哪个好用?4款大多数人常用的软件~
- Hadoop高可用集群搭建及API调用(hadoop3高可用)
- lombok注解@Data没有toString和getter、setter问题
- Apache Felix介绍(apache fineract)
- Spring Boot官方推荐的Docker镜像编译方式-分层jar包
- Gradle 使用手册(gradle详细教程)
- 字节二面:为什么SpringBoot的 jar可以直接运行?
- 标签列表
-
- 下划线是什么 (87)
- 精美网站 (58)
- qq登录界面 (90)
- nginx 命令 (82)
- nginx .http (73)
- nginx lua (70)
- nginx 重定向 (68)
- Nginx超时 (65)
- nginx 监控 (57)
- odbc (59)
- rar密码破解工具 (62)
- annotation (71)
- 红黑树 (57)
- 智力题 (62)
- php空间申请 (61)
- 按键精灵 注册码 (69)
- 软件测试报告 (59)
- ntcreatefile (64)
- 闪动文字 (56)
- guid (66)
- abap (63)
- mpeg 2 (65)
- column (63)
- dreamweaver教程 (57)
- excel行列转换 (56)
本文暂时没有评论,来添加一个吧(●'◡'●)