2016-12-27 1 views
1

http-> https redirection + non-www-> www 리디렉션을 구성했습니다. https로 리디렉션되지 않도록 두 경로를 제외하고 싶습니다. 나는 많은 가능한 구성을 시도했다, 나는 404를 얻는다 또는 나는 https 버전에 방향을 바꾼다.위치 예외가있는 nginx/php-fpm - 404

는 여기에/LOC2/경로를 얻을 수하려고 할 때, 404을 반환 현재 설정, (#curl http://www.server.dev/loc2/18a9BM4Lay)입니다 :

server { 
    listen 80; 
    listen [::]:80; 
    server_name server.dev; 
    location/{ 
return 301 https://$server_name$request_uri; 
    } 
    location /loc1/ { 
     try_files $uri $uri/ /index.php?$args; 

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

server { 
    listen 80; 
    listen [::]:80; 
    server_name www.server.dev; 
    root /var/www/web/server/public; 

    location/{ 
# return 301 https://$server_name$request_uri; 
    } 

     location ^~ /loc1/ { 
#  root /var/www/web/server/public; 
    index index.php; 
#  try_files $uri $uri/ /index.php?$args; 
     include pool_web.conf; 
     } 

     location ^~ /loc2/ { 
#  root /var/www/web/server/public; 
    index index.php; 
#  try_files $uri $uri/ /index.php?$args; 
     location ~ \.php$ { 
       # regex to split $uri to $fastcgi_script_name and $fastcgi_path 
       fastcgi_split_path_info ^(.+\.php)(/.+)$; 
       # Check that the PHP script exists before passing it 
       try_files $fastcgi_script_name =404; 
       # Bypass the fact that try_files resets $fastcgi_path_info 
       # see: http://trac.nginx.org/nginx/ticket/321 
       set $path_info $fastcgi_path_info; 
       fastcgi_param PATH_INFO $path_info; 
       include fastcgi.conf; 
       fastcgi_read_timeout 360s; 
       fastcgi_intercept_errors on; 

       fastcgi_pass unix:/var/run/server-php7.0-fpm.sock; 
    } 
# include pool_web.conf; 

     } 

     } 


server { 
# listen 80; 
# listen [::]:80; 

    listen 443 ssl http2; 

    ssl_certificate /etc/ssl/server.crt; 
    ssl_certificate_key /etc/ssl/server.key; 

    server_name server.dev; 
    rewrite ^ $scheme://www.server.dev$request_uri? permanent; 
} 

server { 
# listen 80; 

    listen 443 ssl http2; 

    ssl_certificate /etc/ssl/server.crt; 
    ssl_certificate_key /etc/ssl/server.key; 

    server_name www.server.dev; 

    root /var/www/web/server/public; 

    index index.php; 

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

    location /images/ { 
     try_files $uri =404; 
    } 

    location ~ \.php$ { 
     include pool_web.conf; 
    } 

    location ~ \.(css|htc|less|js|js2|js3|js4)$ { 
     expires 31536000s; 
     add_header Pragma "public"; 
     add_header Cache-Control "max-age=31536000, public"; 
    } 

    location ~ \.(asf|asx|wax|wmv|wmx|avi|bmp|class|divx|doc|docx|eot|exe|gif|gz|gzip|ico|jpg|jpeg|jpe|mdb|mid|midi|mov|qt|mp3|m4a|mp4|m4v|mpeg|mpg|mpe|mpp|otf|odb|odc|odf|odg|odp|ods|odt|ogg|pdf|png|pot|pps|ppt|pptx|ra|ram|svg|svgz|swf|tar|tif|tiff|ttf|ttc|wav|wma|wri|woff|xla|xls|xlsx|xlt|xlw|zip)$ { 
     expires 31536000s; 
     add_header Pragma "public"; 
     add_header Cache-Control "max-age=31536000, public"; 
    } 
} 
+0

'/ var/www/web/server/public/loc2/18a9BM4Lay'라는 파일이 있습니까? 아니면 다른 일이 일어날 것을 기대합니까? –

+0

해당 파일이 없습니다. 오히려 index.php는/loc2/경로를 처리합니다. – syst0m

답변

0

당신은 기본 핸들러를 정의하는 try_files 문을 추가해야합니다. index 지시문은 디렉토리가 지정된 경우에만 작동합니다. 예를 들어

:

location ^~ /loc2/ { 
    try_files $uri $uri/ /loc2/index.php; 
    ... 
} 

은 자세한 내용은 this document를 참조하십시오.

+0

2.'location^~/loc2/{ try_files $ uri $ /iindex.php?$args; \t ... \t} ' 은 HTTPS로 리디렉션 : #curl http://www.server.dev/loc2/18ayBMOLVy -L -k -I HTTP/1.1 301 이전 영구적으로 서버 : nginx를/1.10.1 (Ubuntu) 날짜 : 2014 년 12 월 27 일 15시 43 분 14 초 GMT 콘텐츠 유형 : text/html 콘텐츠 길이 : 194 연결 : 연결 유지 위치 : https : //www.server .dev/loc2/18ayBMOLVy HTTP/1.1 200 OK – syst0m

+0

1. 위치^~/loc2/{try_files $ uri $ uri//loc2/index.php?$args; ...}'생성 :'* 내부적으로 "/loc2/index.php", 클라이언트 : 127.0.0.1, 서버 : www.server.dev, 요청 : "GET/loc2/18ayBMOLVy"로 리다이렉트하면서 재 작성 또는 내부 리다이렉션주기 HTTP/1.1 ", 호스트 :"www.server.dev "'- – syst0m