2014-02-27 5 views
0

내 웹 루트 디렉터리 외부에있는 디렉터리/웹 응용 프로그램이 있습니다.별칭이있는 중첩 된 위치

/var/www/site/htdocs/ 

그리고 외부 응용 프로그램이 위치는 다음과 같습니다 :

/var/www/apps/coolapp/ 

내 질문은 내가 www.mysite.com/coolapp/*처럼 모든 요청/경로를 매핑의 nginx를 구성하는 방법입니다

사이트가 여기에 말 (별표가 와일드 카드로 표시됨) 외부 위치 /var/www/apps/coolapp/? 예를 들어, www.mysite.com/coolapp/test.php는 서버 /var/www/apps/coolapp/test.php이어야합니다.

nginx.conf 파일에 포함 된 production.confalias 지시문을 추가했습니다. .php 파일을 대신 잡는 또 다른 location이 있기 때문에 .php 파일을 제외한 모든 파일에 문제가 없습니다. 그래서 locationalias으로 중첩시켜 .php 파일을 잡았으나 이제는 nginx가 .php 파일 "404 File Not Found"를 찾을 수 없다는 것을 알려줍니다. 여기 production.conf 현재

server { 
    listen 80; 
    listen 443 ssl; 

    ssl_certificate  /blah/blah/blah; 
    ssl_certificate_key /blah/blah/blah; 
    ssl_protocols  blah blah blah; 
    ssl_ciphers   blahblahblah; 
    ssl_prefer_server_ciphers blahblah; 

    access_log /var/log/nginx/www.mysite.com-access.log; 
    error_log /var/log/nginx/www.mysite.com-error.log error; 

    server_name mysite.com www.mysite.com; 
    root /var/www/site/htdocs; 

    include conf/magento_rewrites.conf; 
    include conf/magento_security.conf; 
    include /var/www/site/nginx/*.conf; 

    #-------CODE IN QUESTION------- 
    location /coolapp/ { 
     alias /var/www/apps/coolapp/; 
     location ~ \.php { 
      # Copied from "# PHP Handler" below 
      fastcgi_param MAGE_RUN_CODE default; 
      fastcgi_param MAGE_RUN_TYPE store; 
      fastcgi_param HTTPS $fastcgi_https; 
      rewrite_log on; 

      # By default, only handle fcgi without caching 
      include conf/magento_fcgi.conf; 
     } 
    } 

    # PHP handler 
    location ~ \.php { 
     ## Catch 404s that try_files miss 
     if (!-e $request_filename) { rewrite//index.php last; } 

     ## Store code is defined in administration > Configuration > Manage Stores 
     fastcgi_param MAGE_RUN_CODE default; 
     fastcgi_param MAGE_RUN_TYPE store; 
     fastcgi_param HTTPS $fastcgi_https; 
     rewrite_log on; 

     # By default, only handle fcgi without caching 
     include conf/magento_fcgi.conf; 
    } 

    # 404s are handled by front controller 
    location @magefc { 
     rewrite ^(.*) /index.php?$query_string last; 
    } 

    # Last path match hands to magento or sets global cache-control 
    location/{ 
     ## Maintenance page overrides front controller 
     index index.html index.php; 
     try_files $uri $uri/ @magefc; 
     expires 24h; 
    } 
} 

conf의 모습입니다/magento_fcgi.conf은 다음과 같습니다 : 여기

fastcgi_pass phpfpm; 

## Tell the upstream who is making the request 
proxy_set_header Host $host; 
proxy_set_header X-Real-IP $remote_addr; 
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; 
proxy_redirect off; 

# Ensure the admin panels have enough time to complete large requests ie: report generation, product import/export 
proxy_read_timeout 1600s; 

# Ensure PHP knows when we use HTTPS 
fastcgi_param HTTPS   $fastcgi_https; 

## Fcgi Settings 
include      fastcgi_params; 
fastcgi_connect_timeout  120; 
fastcgi_send_timeout   320s; 
fastcgi_read_timeout   1600s; 
fastcgi_buffer_size   128k; 
fastcgi_buffers 512   64k; 
fastcgi_busy_buffers_size  128k; 
fastcgi_temp_file_write_size 256k; 
fastcgi_intercept_errors  off; 
fastcgi_index index.php; 
fastcgi_param SCRIPT_FILENAME /var/www/apps/coolapp$fastcgi_script_name; 
fastcgi_param SCRIPT_NAME  $fastcgi_script_name; 
# nginx will buffer objects to disk that are too large for the buffers above 
fastcgi_temp_path    /tmpfs/nginx/tmp 1 2; 
#fastcgi_keep_conn    on; # NGINX 1.1.14 
expires      off; ## Do not cache dynamic content 

내가

2014/02/28 11:10:17 [error] 9215#0: *933 connect() failed (111: Connection refused) while connecting to upstream, ................. client: x.x.x.x, server: mysite.com, request: "GET /coolapp/test.php HTTP/1.1", upstream: "fastcgi://[::1]:9000", host: "www.mysite.com" 
2014/02/28 11:10:17 [error] 9215#0: *933 FastCGI sent in stderr: "Primary script unknown" while reading response header from upstream, client: x.x.x.x, server: mysite.com, request: "GET /coolapp/test.php HTTP/1.1", upstream: "fastcgi://127.0.0.1:9000", host: "www.mysite.com" 
2014/02/28 11:11:59 [error] 9220#0: *1193 FastCGI sent in stderr: "Primary script unknown" while reading response header from upstream, client: x.x.x.x, server: mysite.com, request: "GET /coolapp/test.php HTTP/1.1", upstream: "fastcgi://127.0.0.1:9000", host: "www.mysite.com" 

사람을합니까에서는 error.log에서 가져온 몇 가지 오류 메시지입니다 내가 뭘 잘못하고 있는지 알아?

+0

'mage_rewrites.conf'에 무엇이 있는지 알 수 없으므로 잘못된 것이 없습니다. – Melvyn

+0

몇 가지 테스트가 끝나면 별칭 지시문을 사용할 때'$ uri'가 업데이트되지 않는 것으로 보입니다 :'$ uri'는 여전히'/ coolapp /'접두사가 붙습니다. 이것은 문서와 모순되기 때문에 버그 일 수 있습니다. 나는 이것이 루트가 어떻게 작동해야 하는지를 확신합니다. – Zenexer

답변

0

두 번째로 커피를 읽습니다. 포함 된 fastcgi 구성에서 SCRIPT_FILENAME을 가져 와서 두 위치 블록에 설정하십시오. 이 문제가 해결되지 않으면 coolapp 위치에서 doc 루트 경로를 하드 코딩하고 문제가 해결되는지 확인하십시오.

+0

답변 해 주셔서 감사합니다. coolapp 위치에서'doc root path hardcode' 코드가 어떻게 보이는지 보여줄 수 있습니까? 어떻게 들릴지 모르겠지만'root/var/www/site/htdocs '를 넣기를 원한다. 내가 도움이되는 방법을 알지 못한다. 상속되어야한다고 생각했다. –

+0

fastcgi_param 비트 SCRIPT_FILENAME에서 $ document_root를'/ var/www/apps/coolapp'로 바꿉니다. 나는 변수가 어수선하고 하드 코딩이 의심 스럽다는 것을 확인했다. – Melvyn

+0

아, 아주 좋아. 나는 점점 더 가까워지고 있다고 생각한다. 나는 그 행을'/ var/www/apps/coolapp $ fastcgi_script_name; '으로 바꿨다. 이것은 두 위치 블록 모두에서 필요하지 않아야한다. 그렇다면 fcgi.conf에서 정상이어야합니다. 그러나 나는 여전히 같은 결과를 얻고 있습니다. 게시물에서 내 코드를 업데이트하고 nginx 오류 메시지를 추가합니다. –

1

이것은 최신 버전에서 수정 된 것으로 보입니다. SCRIPT_FILENAME$request_filename으로 설정된 경우 예상대로 작동합니다. (이전 버전과 다른 점은 $request_filename이 모든 경우에 작동하지 않습니다.) 또한 내부 위치 블록에서 try_files 지시어를 생략해야합니다. $uri의 재평가가 $request_filename으로 표시됩니다.