>  기사  >  백엔드 개발  >  nginx 하위 디렉터리에 하위 프로젝트가 추가되면 CSS 및 기타 리소스에 액세스할 수 없습니다.

nginx 하위 디렉터리에 하위 프로젝트가 추가되면 CSS 및 기타 리소스에 액세스할 수 없습니다.

WBOY
WBOY원래의
2016-10-12 10:04:112055검색

두 개의 프로젝트가 있습니다. 하나는 phpcms의 것이고 다른 하나는 yii2.0 프레임워크의 것입니다. 서버는 nginx를 사용합니다. 이제 yii 프로젝트를 하위 디렉터리로 직접 가져온 다음 http://domain을 사용하려고 합니다. com/ 하위 디렉터리에 액세스할 수 있지만 index는configuration/sub디렉토리를 통해 액세스할 수 있지만 그림, CSS 등 페이지의 리소스 파일은 로드할 수 없습니다. 그림 링크는 http://domain.com/sub디렉토리입니다. /public/images/blue_icon.png 하지만 아니면 하위 디렉토리 아래의 index.php로 리디렉션됩니까? 문제가 무엇입니까?

<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>

답글 내용:

두 개의 프로젝트가 있습니다. 하나는 phpcms의 것이고 다른 하나는 yii2.0 프레임워크의 것입니다. 서버는 nginx를 사용합니다. 이제 yii 프로젝트를 하위 디렉터리로 직접 가져온 다음 http://domain을 사용하려고 합니다. com/ 하위 디렉터리에 액세스할 수 있지만 index는configuration/subdirectory를 통해 액세스할 수 있지만 그림, CSS 등 페이지의 리소스 파일은 로드할 수 없습니다. 그림 링크는 http://domain.com/subdirectory입니다. /public/images/blue_icon.png 하지만 아니면 하위 디렉토리 아래의 index.php로 리디렉션됩니까? 문제가 무엇입니까?

<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>
성명:
본 글의 내용은 네티즌들의 자발적인 기여로 작성되었으며, 저작권은 원저작자에게 있습니다. 본 사이트는 이에 상응하는 법적 책임을 지지 않습니다. 표절이나 침해가 의심되는 콘텐츠를 발견한 경우 admin@php.cn으로 문의하세요.