2016-12-26 1 views
1

나는 클라이언트 웹 사이트를 업로드하는 데 dev 서버가 있습니다. 모든 WordPress 사이트에는 자체 DB와 디렉토리가 있습니다 (모든 사이트는 독립적입니다). 하나의 서버 블록이 있습니다. 내 문제는이 나를 위해 작동, 예쁜 영구 링크 함께 : 나는 각 사이트에하지만 행운의 위치 블록을 추가하는 한 번에 대신 할 수있는 방법을 찾고 있었어요하위 디렉토리에있는 여러 WordPress 사이트에 대한 자동 예쁜 링크를위한 NGINX 구성

server_name dev.example.tld; 

    location = /favicon.ico { log_not_found off; access_log off; } 
    location = /robots.txt { log_not_found off; access_log off; allow all; } 

    location/{ 
      try_files $uri $uri/ =404; 
      add_header 'Cache-Control' 'no-store, no-cache, must-revalidate, proxy-revalidate, max-$ 
      expires off; 
    } 

    location /site_1/ { 
      index index.php; 
      try_files $uri $uri/ /site_1/index.php?$args; 
    } 

    location /site_2/ { 
      index index.php; 
      try_files $uri $uri/ /site_2/index.php?$args; 
    } 

.

답변

1

당신은 정규 표현식으로 location을 변경하고 사이트 이름 캡처 할 수 있습니다 : 또는

location ~ ^(?<site>/[^/]+) { 
    try_files $uri $uri/ $site/index.php?$args; 
} 

를 재 작성 사용하여 동일한 효과를 달성 :

location/{ 
    try_files $uri $uri/ @rewrite; 
} 
location @rewrite { 
    rewrite ^(/[^/]+) $1/index.php last; 
    return 404; 
} 
+0

은'site' 변수가이다 예를 들어 ** dev.example.tld **? 사용했을 때 오류가 표시됩니다 : – Ritterwise

+0

두 번째 예제에서 죄송합니다. 잘라내 기와 붙여 넣기 오류는 물론 '$ 1'이어야합니다. '$ site' 또는'$ 1'은 URI의 첫 번째 경로 세그먼트입니다. '/ site_1' 또는'/ site_2'를 입력하십시오. 서버 이름이 필요한 경우 :'$ host','$ server_name' 또는'$ http_host' (모두 약간 다릅니다 - 자세한 내용은이 링크 참조) (http://nginx.org/en/docs/http /ngx_http_core_module.html#var_host)) –

관련 문제