Nginx子目录中的PHP应用程序

时间:2018-06-06 08:16:09

标签: php codeigniter nginx

我使用的是Ubuntu 16.04,Nginx 1.10.3和PHP 7.0。示例PHP应用程序是CodeIgniter 3.1.5。

我正在尝试在我的网站www.example.com(works)的根目录下运行一个静态页面,其中包含多个其他CodeIgniter应用程序,每个应用程序都在子目录中运行,网址为www.example.com/client-a,www.example.com / client-b等。

我的root上的静态页面运行正常,但是当重定向到子目录中的应用程序时,没有样式表和脚本被加载导致404错误。路由工作。

后续应用程序的应用程序文件不会彼此存在。应用程序根目录存在于/var/www/example/public_html中,而#34;嵌套"应用程序位于/var/www/client_a/public_html/var/www/client_b/public_html等。

这是我的Nginx服务器块:

server {
    listen 80 default_server;
    listen [::]:80 default_server;

    server_name example.com www.example.com;    
    root /var/www/example/public_html;

    index index.php index.html index.htm;       

    location / {
        try_files $uri $uri/ /index.php$is_args$args;
    }

    location /client-a {
            alias /var/www/client_a/public_html;
            try_files $uri $uri/ @nested;

            location ~ \.php$ {
                include snippets/fastcgi-php.conf;
                fastcgi_param SCRIPT_FILENAME $request_filename;
                fastcgi_pass unix:/var/run/php/php7.0-fpm.sock;
            }
    }

    location @nested {
        rewrite /client_a/(.*)$ /client_a/index.php?/$1 last;
    }

    location ~ \.php$ {
        include snippets/fastcgi-php.conf;
        fastcgi_pass unix:/run/php/php7.0-fpm.sock;
    }

    location ~*  \.(jpg|jpeg|png|gif|ico|css|js)$ {
        expires 30d;
    }

    location ~ /\.ht {
        deny all;
    }
}

0 个答案:

没有答案
相关问题