
저는 최근 Apache 2.4에서 NGINX 1.7.12로 변경했는데 그 속도와 다양성이 마음에 들었습니다. 불행하게도 나는 아직도 SERVER 블록이 올바르게 작동하도록 하지 못했습니다.
나는 PHP를 제공하기 위해 FASTCGI php5-fpm을 사용하고 있습니다. 내 NGINX의 루트는 /var/www입니다. MC라는 주요 웹사이트는 www.example.com에 있으며 /var/www/mc에서 서비스됩니다.
동시에 나는 /var/www/masmagazine에서 제공되는 기본 사이트 www.example.com/masmagazine의 하위 디렉토리로 "masmagazine"이라는 WordPress 블로그를 가지고 있습니다.
저는 두 개의 서로 다른 서버 블록 파일을 통해 두 웹사이트(메인 사이트와 블로그)가 작동하도록 관리했습니다. 그러나 두 웹사이트가 동시에 작동하도록 올바르게 결합할 수는 없습니다.
www.example.com의 작동 중인 서버 블록:
server {
listen 80 default_server;
listen [::]:80 default_server;
server_name www.example.com;
root /var/www/mc;
index index.php index.html index.htm;
location / {
try_files $uri $uri/ /index.php;
}
location /includes {
rewrite ^/includes/css/coupon-unit.css /includes/css/coupon-unit.php;
rewrite ^/includes/css/mobile-menu.css /includes/css/mobile-menu.php;
rewrite ^/includes/css/mobile.css /includes/css/mobile.php;
rewrite ^/includes/css/style.css /includes/css/style.php;
rewrite ^/includes/css/users.css /includes/css/users.php;
}
location /feed {
rewrite ^/feed/ /feed.php break;
}
location /internationalsitemap {
rewrite ^/internationalsitemap.xml /internationalsitemap.php;
}
location /page {
rewrite ^/page-sitemap.xml /sitemap.php?site=page;
rewrite ^/page-child-sitemap.xml /sitemap.php?site=childstore;
}
location /newstores {
rewrite ^/newstores-sitemap.xml /sitemap.php?site=store;
}
location /coupon_category {
rewrite ^/coupon_category-sitemap.xml /sitemap.php?site=category;
}
location ~ \.php$ {
try_files $uri =404;
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_pass unix:/var/run/php5-fpm.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
}
www.example.com/masmagazine의 작업 서버 블록:
server {
listen 80 default_server;
listen [::]:80 default_server;
server_name www.example.com;
index index.php index.html index.htm;
root /var/www;
location / {
try_files $uri $uri/ /index.php;
}
location /masmagazine {
alias /var/www/masmagazine;
try_files $uri $uri/ /masmagazine/index.php?$args;
}
location ~ \.php$ {
try_files $uri =404;
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_pass unix:/var/run/php5-fpm.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
}
두 가지를 결합하면 masmagazine에 대해 404 찾을 수 없음 오류가 발생합니다. 아마도 PHP 위치 블록 내에서 masmagazine의 하위 디렉터리 상황을 올바르게 처리하지 못하기 때문일 것입니다.
어떤 도움이라도 정말 감사하겠습니다! 나는 정말로 이것에 붙어 있습니다.
Apache에서 효과가 있었던 것은 다음과 같습니다.
<VirtualHost *:80>
ServerName http://www.example.com
DocumentRoot /var/www/mc
<Directory /var/www/mc/>
Options FollowSymLinks
AllowOverride All
DirectoryIndex index.php index.html
Require all granted
</Directory>
Alias /masmagazine /var/www/masmagazine
<Directory /var/www/masmagazine/>
Options FollowSymLinks
AllowOverride All
DirectoryIndex index.php index.html
Require all granted
</Directory>
</VirtualHost>
업데이트:
Tero의 제안에 따라 다음과 같이 수정된 서버 블록을 사용했습니다.
server {
listen 80 default_server;
listen [::]:80 default_server;
server_name www.example.com;
root /var/www/mc;
index index.php index.html index.htm;
location / {
try_files $uri $uri/ /index.php;
}
location /masmagazine {
alias /var/www/masmagazine;
try_files $uri $uri/ /index.php?$args;
}
location /includes {
rewrite ^/includes/css/coupon-unit.css /includes/css/coupon-unit.php;
rewrite ^/includes/css/mobile-menu.css /includes/css/mobile-menu.php;
rewrite ^/includes/css/mobile.css /includes/css/mobile.php;
rewrite ^/includes/css/style.css /includes/css/style.php;
rewrite ^/includes/css/users.css /includes/css/users.php;
}
location /feed {
rewrite ^/feed/ /feed.php break;
}
location /internationalsitemap {
rewrite ^/internationalsitemap.xml /internationalsitemap.php;
}
location /page {
rewrite ^/page-sitemap.xml /sitemap.php?site=page;
rewrite ^/page-child-sitemap.xml /sitemap.php?site=childstore;
}
location /newstores {
rewrite ^/newstores-sitemap.xml /sitemap.php?site=store;
}
location /coupon_category {
rewrite ^/coupon_category-sitemap.xml /sitemap.php?site=category;
}
location ~ \.php$ {
try_files $uri =404;
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_pass unix:/var/run/php5-fpm.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
}
www.example.com/masmagazine을 요청하면 결과는 404 오류입니다. 로그는 PHP 프로세서가 var/www/masmagazine/에서 찾아야 할 때 var/www/mc/masmagazine/index.php에서 masmagazine의 index.php를 (index 지시문에 따라) 처리하려고 시도하고 있음을 보여줍니다. index.php.
로그의 관련 부분은 다음과 같습니다.
2015/05/22 12:00:54 [debug] 2108#0: *1 http request line: "GET /masmagazine/ HTTP/1.1"
2015/05/22 12:00:54 [debug] 2108#0: *1 http uri: "/masmagazine/"
2015/05/22 12:00:54 [debug] 2108#0: *1 http args: ""
2015/05/22 12:00:54 [debug] 2108#0: *1 http exten: ""
2015/05/22 12:00:54 [debug] 2108#0: *1 test location: "/"
2015/05/22 12:00:54 [debug] 2108#0: *1 test location: "internationalsitemap"
2015/05/22 12:00:54 [debug] 2108#0: *1 test location: "newstores"
2015/05/22 12:00:54 [debug] 2108#0: *1 test location: "masmagazine"
2015/05/22 12:00:54 [debug] 2108#0: *1 test location: ~ "\.php$"
2015/05/22 12:00:54 [debug] 2108#0: *1 using configuration "/masmagazine"
2015/05/22 12:00:54 [debug] 2108#0: *1 http cl:-1 max:1048576
2015/05/22 12:00:54 [debug] 2108#0: *1 rewrite phase: 3
2015/05/22 12:00:54 [debug] 2108#0: *1 post rewrite phase: 4
2015/05/22 12:00:54 [debug] 2108#0: *1 generic phase: 5
2015/05/22 12:00:54 [debug] 2108#0: *1 generic phase: 6
2015/05/22 12:00:54 [debug] 2108#0: *1 generic phase: 7
2015/05/22 12:00:54 [debug] 2108#0: *1 access phase: 8
2015/05/22 12:00:54 [debug] 2108#0: *1 access phase: 9
2015/05/22 12:00:54 [debug] 2108#0: *1 access phase: 10
2015/05/22 12:00:54 [debug] 2108#0: *1 access phase: 11
2015/05/22 12:00:54 [debug] 2108#0: *1 post access phase: 12
2015/05/22 12:00:54 [debug] 2108#0: *1 try files phase: 13
2015/05/22 12:00:54 [debug] 2108#0: *1 http script var: "/masmagazine/"
2015/05/22 12:00:54 [debug] 2108#0: *1 trying to use file: "/" "/var/www/masmagazine/"
2015/05/22 12:00:54 [debug] 2108#0: *1 http script var: "/masmagazine/"
2015/05/22 12:00:54 [debug] 2108#0: *1 trying to use dir: "/" "/var/www/masmagazine/"
2015/05/22 12:00:54 [debug] 2108#0: *1 try file uri: "/masmagazine/"
2015/05/22 12:00:54 [debug] 2108#0: *1 content phase: 14
2015/05/22 12:00:54 [debug] 2108#0: *1 content phase: 15
2015/05/22 12:00:54 [debug] 2108#0: *1 open index "/var/www/masmagazine/index.php"
2015/05/22 12:00:54 [debug] 2108#0: *1 internal redirect: "/masmagazine/index.php?"
2015/05/22 12:00:54 [debug] 2108#0: *1 rewrite phase: 1
2015/05/22 12:00:54 [debug] 2108#0: *1 test location: "/"
2015/05/22 12:00:54 [debug] 2108#0: *1 test location: "internationalsitemap"
2015/05/22 12:00:54 [debug] 2108#0: *1 test location: "newstores"
2015/05/22 12:00:54 [debug] 2108#0: *1 test location: "masmagazine"
2015/05/22 12:00:54 [debug] 2108#0: *1 test location: ~ "\.php$"
2015/05/22 12:00:54 [debug] 2108#0: *1 using configuration "\.php$"
2015/05/22 12:00:54 [debug] 2108#0: *1 http cl:-1 max:1048576
2015/05/22 12:00:54 [debug] 2108#0: *1 rewrite phase: 3
2015/05/22 12:00:54 [debug] 2108#0: *1 post rewrite phase: 4
2015/05/22 12:00:54 [debug] 2108#0: *1 generic phase: 5
2015/05/22 12:00:54 [debug] 2108#0: *1 generic phase: 6
2015/05/22 12:00:54 [debug] 2108#0: *1 generic phase: 7
2015/05/22 12:00:54 [debug] 2108#0: *1 access phase: 8
2015/05/22 12:00:54 [debug] 2108#0: *1 access phase: 9
2015/05/22 12:00:54 [debug] 2108#0: *1 access phase: 10
2015/05/22 12:00:54 [debug] 2108#0: *1 access phase: 11
2015/05/22 12:00:54 [debug] 2108#0: *1 post access phase: 12
2015/05/22 12:00:54 [debug] 2108#0: *1 try files phase: 13
2015/05/22 12:00:54 [debug] 2108#0: *1 http script var: "/masmagazine/index.php"
2015/05/22 12:00:54 [debug] 2108#0: *1 trying to use file: "/masmagazine/index.php" "/var/www/mc/masmagazine/index.php"
2015/05/22 12:00:54 [debug] 2108#0: *1 trying to use file: "=404" "/var/www/mc=404"2015/05/22 12:00:54 [debug] 2108#0: *1 http finalize request: 404, "/masmagazine/index.php?" a:1, c:2
2015/05/22 12:00:54 [debug] 2108#0: *1 http special response: 404, "/masmagazine/index.php?"
2015/05/22 12:00:54 [debug] 2108#0: *1 http set discard body
2015/05/22 12:00:54 [debug] 2108#0: *1 xslt filter header
2015/05/22 12:00:54 [debug] 2108#0: *1 HTTP/1.1 404 Not Found
답변1
첫 번째 블록에 다음 블록을 추가하세요 server
.
location /masmagazine {
alias /var/www/masmagazine;
try_files $uri $uri/ /index.php?$args;
}
try_files
위치 블록 내부는 여기에서 명령문을 사용하여 정의된 블록 루트 디렉터리를 기준으로 작동 location
합니다 alias
.