Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/codeigniter/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Nginx子目录中的PHP应用程序_Php_Codeigniter_Nginx - Fatal编程技术网

Nginx子目录中的PHP应用程序

Nginx子目录中的PHP应用程序,php,codeigniter,nginx,Php,Codeigniter,Nginx,我使用的是Ubuntu 16.04、Nginx 1.10.3和PHP7.0。示例PHP应用程序是CodeIgniter 3.1.5 我试图在我的网站www.example.com(works)的根目录下运行一个静态页面,并在www.example.com/client-a、www.example.com/client-b等子目录中运行多个其他CodeIgniter应用程序 我的根目录下的静态页面运行正常,但是当重定向到子目录下的应用程序时,没有加载任何样式表和脚本,从而导致404个错误。不过,路

我使用的是Ubuntu 16.04、Nginx 1.10.3和PHP7.0。示例PHP应用程序是CodeIgniter 3.1.5

我试图在我的网站www.example.com(works)的根目录下运行一个静态页面,并在www.example.com/client-a、www.example.com/client-b等子目录中运行多个其他CodeIgniter应用程序

我的根目录下的静态页面运行正常,但是当重定向到子目录下的应用程序时,没有加载任何样式表和脚本,从而导致404个错误。不过,路由是可行的

后续应用程序的应用程序文件彼此之间不存在。应用程序根存在于
/var/www/example/public_html
中,而“嵌套”应用程序存在于
/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;
    }
}

您在客户端的应用程序中为
base\u url()
设置了什么?加载资产时是否使用前缀
base\u url()
,即
base\u url('assets/css/style.css')
base\u url()
=www.example.com/client-a,并且在加载资产时,我会使用前缀。必须使用(AFAIK)方案和尾部斜线<代码>$config['base\u url']='http://www.example.com/client-a/';。我尝试过,但是它似乎不起作用。您需要使用
location^~/client-a
,否则将找不到嵌套位置。