nginx配置多目录访问

【字号: 日期:2022-07-02浏览:54作者:雯心

问题描述

操作系统:ubuntu13.10服务器:nginx 1.6

在nginx配置根据url指向不同访问不同的目录使用location /目录名 { ... } 可以做到不同的目录访问

但是我想搭建laravel4 framework,想通过/coolwifi/test就直接解析成/coolwifi/public/index.php/test,但是会报错:Symfony Component HttpKernel Exception NotFoundHttpException但是通过http://localhost/coolwifi/public/index.php/test访问是可以的我该怎么做?

default配置文件如下:

server { listen 80 default_server; listen [::]:80 default_server ipv6only=on; root /home/kimhwawoon/nginx; index index.php index.html index.htm; # Make site accessible from http://localhost/ server_name localhost; location /coolwifi/ {index index.php;#if (!-e $request_filename) {# rewrite ^/(.*)$ /public/index.php?$1 last;# break;#}try_files $uri $uri/ /coolwifi/public/index.php?$args;}location /phpmyadmin/ {index index.phptry_files $uri $uri/ /phpmyadmin/index.php?$args;} location /swagger/ {index index.html index.php; } location /doc/ {alias /usr/share/doc/;autoindex on;allow 127.0.0.1;allow ::1;deny all; }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;}}

问题解答

回答1:

按照单个server怎么弄都不行,最后设置了多个server可以解决问题,并且在本机的/etc/hosts配置了多个域名指向本地,使用不同的域名区分不同的目录

回答2:

请问楼主使用过phalcon吗?最近我学习了下phalcon,但是按你这样设置所有的路由都重定向到了index/index了,请问你有解决方案吗?谢谢

相关文章: