nginx配置多目錄訪問
天蓬老师
天蓬老师 2017-05-16 17:27:14
0
2
831

作業系統: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? last;
                #    break;
                #}
                try_files $uri $uri/ /coolwifi/public/index.php?$args;
        }

        location /phpmyadmin/ {
                index index.php
                try_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;
        }
}
天蓬老师
天蓬老师

欢迎选择我的课程,让我们一起见证您的进步~~

全部回覆(2)
黄舟

按照單一server怎麼弄都不行,最後設定了多個server可以解決問題,並且在本機的/etc/hosts配置了多個網域指向本地,使用不同的網域區分不同的目錄

巴扎黑

請問樓主使用過phalcon嗎?最近我學了下phalcon,但是按你這樣設定所有的路由都重定向到了index/index了,請問你有解決方案嗎?謝謝

熱門教學
更多>
最新下載
更多>
網站特效
網站源碼
網站素材
前端模板
關於我們 免責聲明 Sitemap
PHP中文網:公益線上PHP培訓,幫助PHP學習者快速成長!