2017-11-15 13 views
1

docker 컨테이너에서 nginx를 실행 중입니다. 개인 파일과 프로젝트에 액세스하려면 서브 디렉토리 /web/을 갖고 싶습니다. 그것은 또한 PHP를 지원해야합니다.Nginx 서브 디렉토리 루트 (PHP 포함)

다음은 내가 실행하고있는 내용이지만 domain-a.com/web은 404를 유지합니다. 동일한 PHP 블록이 서브 도메인에서 작동하지만 직접적으로 server{} 블록에서 작동하므로 PHP가 작동하는 것으로 확인되었습니다. 파일이 /etc/nginx/www에있는 경우

http { 

    server { 
     listen  443 ssl; 
     server_name domain-a.com domain-b.com; 

     # Mime types 
     include /etc/nginx/confs/mime.types; 

     # SSL 
     include /etc/nginx/confs/nginx-ssl.conf; 

     # Proxy to organizr 
     # This works 
     location/{ 
      proxy_pass http://organizr/; 
      proxy_set_header Host $http_host; 
      proxy_set_header X-Real-IP $remote_addr; 
      proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; 
      proxy_set_header X-Forwarded-Proto $scheme; 

      # HTTP 1.1 support 
      proxy_http_version 1.1; 
      proxy_set_header Connection ""; 
     } 

     # Root folder for my personal files/projects 
     # Doesn't work 
     location /web { 
      index index.php index.html; 
      root /etc/nginx/www; 

      location ~ \.php$ { 
       try_files $uri =404; 
       fastcgi_split_path_info ^(.+\.php)(/.+)$; 
       fastcgi_pass php:9000; 
       fastcgi_index index.php; 
       include fastcgi_params; 
       fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; 
       fastcgi_param PATH_INFO $fastcgi_path_info; 
      } 
     } 
    } 
} 
+0

파일도 하위 디렉토리 (예 :'/ etc/nginx/www/web /')에 있습니까? –

+0

@RichardSmith 아니요, 그들은'/ etc/nginx/www /'에 있습니다 – Bob

답변

1

당신은 오히려 root 지시어보다 alias 지시어를 사용해야합니다. 자세한 내용은 this document을 참조하십시오. 예를 들어

:

location ^~ /web { 
    index index.php index.html; 
    alias /etc/nginx/www; 

    if (!-e $request_filename) { rewrite^/web/index.php last; } 

    location ~ \.php$ { 
     if (!-f $request_filename) { return 404; } 

     fastcgi_pass php:9000; 
     include fastcgi_params; 
     fastcgi_param SCRIPT_FILENAME $request_filename; 
    } 
} 

사용 $request_filename는 별칭 파일에 대한 올바른 경로를 얻을 수있다. this issue으로 인해 alias으로 try_files을 피하십시오. if의 사용에 대해서는 this caution을 참조하십시오.

+0

고마워요. 이것이 답입니다. 곧바로 일했다. – Bob