2013-07-13 2 views
0

나는 내용의 기본적으로 3 가지 유형과의 nginx 서버 설정하려고 : 하위 폴더에, nginx의 포럼 하위 폴더에서 정적 파일을 제공하는 방법은 무엇입니까?

  • AQ & 포럼 CodeIgniter를 실행,

    • 주요 웹 사이트 (Question2Answer에서 실행) /qa
    • (다양한 위치에서 /qa 포함)
    • 정적 파일은

    나는 여러 가지 문제로 실행하고 있습니다. (서버 블록 내부) 나의 현재 설정은 다음과 같습니다이 대부분 이러한 문제를 제외하고 노력하고 있습니다

    # Q2A 
    if ($request_uri ~* "^/qa/") { 
        rewrite ^/qa/(.*)$ /qa/index.php?qa-rewrite=$1 last; 
    } 
    # CI 
    if (!-e $request_filename) { 
        rewrite ^(.+)$ /index.php?$1 last; 
    } 
    location/{ 
        index index.php index.html; 
    } 
    location ~ \.php$ { 
         try_files $uri =404; 
    
         fastcgi_cache one; 
         fastcgi_cache_key $scheme$host$request_uri; 
         fastcgi_cache_valid 200 302 304 5m; 
         fastcgi_cache_valid 301 1h; 
    
         include /etc/nginx/fastcgi_params; 
         fastcgi_pass unix:/var/run/php-fastcgi/php-fastcgi.socket; 
         fastcgi_index index.php; 
         fastcgi_param SCRIPT_FILENAME /srv/www/site$fastcgi_script_name; 
         fastcgi_param HTTPS off; 
    } 
    

    : 내 응용 프로그램 폴더에있는 PHP 파일에 대한

    • 요청이 실행/분석되고있다. 분명히 이것은 CI 애플 리케이션을 통과하지 않기 때문에 에러를 일으킨다 (변수는 발견되지 않는다). qa 폴더 안에
    • 모든 정적 파일은 Q2A 응용 프로그램에 전달되는하는 대신 같은 위치 블록을 사용하는 것과 내가 수를 잃은 나는 많은 다른 것들을 시도했습니다

    정적 파일로 제공되는 location ~* ^/qa/ {}try_files의 다양한 순열과 같은 행운은 없습니다. 나는 또한 this Wordpress example on the nginx site을 수정하려고 시도했다. 그들 중 대부분은 /qa/으로 끝났습니다. 일부 방법으로는 서버가 원시 PHP 코드를 제공하게되었습니다!

    누구나 적절한 방법으로이를 설정할 수 있습니까?

  • 답변

    1

    교체 또한

    location ~ /qa/(.*)? { 
        try_files $uri /qa/index.php?qa-rewrite=$1&$query_string; 
    } 
    

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

    / 안에 위치 이동 try_files

    로 변환 할 수있는 더 나은 블록

    if ($request_uri ~* "^/qa/") { 
        rewrite ^/qa/(.*)$ /qa/index.php?qa-rewrite=$1 last; 
    } 
    

    location/{ 
        index index.php index.html; 
        try_files $uri /index.php?$request_uri 
    } 
    

    아직도 문제가 있으면 알려주세요.

    +0

    감사합니다. 그러나 어떤 이유에서/qa 디렉토리의 페이지가 디렉토리 자체 인 mysite.com/qa /와 별개로 작동하지 않습니다. 또한, 나는 그것을'location ~ * ^/qa /(.*)?$'로 변경하여 전체 URL인지 확인하고 PHP 코드를 다운로드하도록 요청했습니다! – DisgruntledGoat

    +0

    흠, 나는 약간 잘못된 것이있을 수 있습니다. 다음은 원래 아파치 규칙이다 :'RewriteRule ^. * $ index.php? qa-rewrite = $ 0 & % {QUERY_STRING} [L]' – DisgruntledGoat

    +0

    내가 말했듯이, 내가'location ~'을 사용한다면 ** 다운로드 중이다 ** 실제 PHP 코드, 즉'/ qa/index.php '파일을 다운로드합니다. 왜 그랬을까요? – DisgruntledGoat

    0

    If is evil. 그러나 try_files과 일부 위치 블록을 사용하여 동일한 작업을 수행 할 수 있습니다.

    +0

    이것은 작동하지 않습니다. qa 폴더에서 PHP 코드를 다운로드하라는 메시지가 나타납니다! – DisgruntledGoat

    0

    이것은 nginx를 실행하는 PHP 사이트에서 사용하는 구성을 기반으로합니다.

    참고 이것은 테스트되지 않았지만 약간 수정 된 버전이므로 작동해야합니다.

    (삽입)을 로그 및 루트 지시문에서 서버 값으로 바꾸십시오.

    server { 
        listen 80; 
        access_log /var/log/nginx/(insert).access.log; 
        error_log /var/log/nginx/(insert).error.log; 
        root (insert); 
        server_name (insert); 
        rewrite ^/qa/(.*(?![\.js|\.css])[^.]+)$ /qa/index.php/$1 last; 
        rewrite ^(.*(?![\.js|\.css])[^.]+)$ /index.php/$1 last; 
        location ~ [^/]\.php(/|$) { 
    
         fastcgi_cache one; 
         fastcgi_cache_key $scheme$host$request_uri; 
         fastcgi_cache_valid 200 302 304 5m; 
         fastcgi_cache_valid 301 1h; 
    
         fastcgi_split_path_info ^(.+?\.php)(/.*)$; 
         fastcgi_pass unix:/var/run/php-fastcgi/php-fastcgi.socket; 
         fastcgi_index index.php; 
         include fastcgi_params; 
        } 
    } 
    
    관련 문제