Home  >  Article  >  Backend Development  >  Add subprojects to nginx subdirectory, css and other resources cannot be accessed

Add subprojects to nginx subdirectory, css and other resources cannot be accessed

WBOY
WBOYOriginal
2016-10-12 10:04:112080browse

There are two projects, one is from phpcms, and the other is from the yii2.0 framework. The server uses nginx. Now I want to take the yii project directly as a subdirectory and then use it through the http://domain.com/ subdirectory. to access, but the index can be accessed through the configuration/subdirectory, but the resource files of the page such as pictures, css, etc. cannot be loaded. The picture link is http://domain.com/subdirectory/public/images/blue_icon.png, but it still does. Redirect to index.php under the subdirectory. What is the problem?

<code>server{
    listen 80;
    server_name domain.com;
    root   /Users/xxx/www/project;
    index index.php;
    
    location /{
        try_files $uri $uri/ /index.php?$args;
        autoindex on;
    }    
    location /blog{
        index index.php index.html;
        try_files $uri $uri/ /blog/index.php?$args;
        autoindex on;
    }
    location ~ ^(.+\.php)(.*)$ {
        root   /Users/xxx/www/project;
        fastcgi_split_path_info ^(.+\.php)(.*)$;
        fastcgi_param PATH_INFO $fastcgi_path_info;
        fastcgi_pass   127.0.0.1:9000;
        fastcgi_index  index.php;
        fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
        include        fastcgi_params;
    }
}</code>

Reply content:

There are two projects, one is from phpcms, and the other is from the yii2.0 framework. The server uses nginx. Now I want to take the yii project directly as a subdirectory and then use it through the http://domain.com/ subdirectory. to access, but the index can be accessed through the configuration/subdirectory, but the resource files of the page such as pictures, css, etc. cannot be loaded. The picture link is http://domain.com/subdirectory/public/images/blue_icon.png, but it still does. Redirect to index.php under the subdirectory. What is the problem?

<code>server{
    listen 80;
    server_name domain.com;
    root   /Users/xxx/www/project;
    index index.php;
    
    location /{
        try_files $uri $uri/ /index.php?$args;
        autoindex on;
    }    
    location /blog{
        index index.php index.html;
        try_files $uri $uri/ /blog/index.php?$args;
        autoindex on;
    }
    location ~ ^(.+\.php)(.*)$ {
        root   /Users/xxx/www/project;
        fastcgi_split_path_info ^(.+\.php)(.*)$;
        fastcgi_param PATH_INFO $fastcgi_path_info;
        fastcgi_pass   127.0.0.1:9000;
        fastcgi_index  index.php;
        fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
        include        fastcgi_params;
    }
}</code>
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn