2017-09-23 14 views
0

나는 nginx에 새로 왔으며 .htaccess를 nginx와 함께 사용하는 방법을 모르며 어디에서 생성 된 코드를 nginx configuration.could에 넣을 수 있습니까? 아무도 이걸 nginx로 변환하도록 도와 주시겠습니까?nginx와 함께 .htaccess를 사용하는 방법과 어디에 넣을까요?

여기 nginx에 어디 정확히이 코드를 넣어 나를 인도하는이 변환 도와주세요 내 htaccess로 파일

<IfModule mod_rewrite.c> 

RewriteCond ${REQUEST_URI} ^.+$ 
RewriteCond %{REQUEST_FILENAME} \.(admin)$ [OR] 
RewriteCond %{REQUEST_FILENAME} -f [OR] 
RewriteCond %{REQUEST_FILENAME} -d [OR] 
RewriteCond %{REQUEST_FILENAME} -l 
RewriteRule^- [L] 
RewriteCond %{QUERY_STRING} [^a-z](cast|char|convert|declare|delete|drop|exec|insert|meta|script|select|set|truncate|update)[^a-z] [NC] 
RewriteRule (.*) - [F] 
RewriteEngine On 
# redirect with username 
Options +FollowSymLinks 
RewriteCond %{REQUEST_FILENAME} !-f 
RewriteCond %{REQUEST_FILENAME} !-d 
RewriteRule ^(admin|assets|include)(.*)?$ /$1$2 [L,QSA,R=301] 
RewriteRule ^user/([a-zA-Z0-9_-]+)$ user.php?username=$1 
RewriteRule ^user/([a-zA-Z0-9_-]+)/$ user.php?username=$1 
RewriteRule ^media/([a-zA-Z0-9_-]+)$ media.php?id=$1 
RewriteRule ^media/([a-zA-Z0-9_-]+)/$ media.php?id=$1 
RewriteRule ^tag/([^/.]+)$ tag.php?tag=$1 [QSA,L] 
RewriteRule ^tag/([^/.]+)/$ tag.php?tag=$1 [QSA,L] 
# turn on the mod_rewrite engine 
RewriteCond %{REQUEST_FILENAME}.php -f 
# IF the request filename with .php extension is a file which exists 
RewriteCond %{REQUEST_URI} !/$ 
# AND the request is not for a directory 
RewriteRule (.*) $1\.php [L] 
# redirect to the php script with the requested filename 



</IfModule> 

입니다. 고맙습니다!

+0

의 nginx는 (읽기)의 .htaccess를 사용하지 않는, 오직 그래 – Mark

+0

을 아파치하지만 지금 nginx에 할 htaccess로 변환하는 방법이? –

답변

0

Nginx는 htaccess 파일을 사용하지 않습니다. Nginx 사이트 설정에서 규칙을 지정해야합니다. . 기존 htaccess 파일을 Nginx conf로 변환하는 데 this과 같은 서비스를 사용할 수 있지만 변환 후에는 잘못된 것이 있는지 다시 확인해야합니다.

아래의 내용은 위의 서비스에서 변경되어 필요한 설정 변경에 대한 정보를 얻지 만 현재 nginx 구성과 관련된 몇 가지 변경 사항이있을 수 있습니다.

location ~ \.(admin)$ { 
} 
location ~ /$ { 
} 
location/{ 
if ($query_string ~* "[^a-z](cast|char|convert|declare|delete|drop|exec|insert|meta|script|select|set|truncate|update)[^a-z]"){ 
    return 403; 
} 
if (!-e $request_filename){ 
     rewrite ^/(admin|assets|include)(.*)?$ /$1$2 redirect; 
    } 
    rewrite ^(.*)$ /$1\.php break; 
} 
location /user { 
    rewrite ^/user/([a-zA-Z0-9_-]+)$ /user.php?username=$1; 
    rewrite ^/user/([a-zA-Z0-9_-]+)/$ /user.php?username=$1; 
} 
location /media { 
     rewrite ^/media/([a-zA-Z0-9_-]+)$ /media.php?id=$1; 
     rewrite ^/media/([a-zA-Z0-9_-]+)/$ /media.php?id=$1; 
} 
location /tag { 
    rewrite ^/tag/([^/.]+)$ /tag.php?tag=$1 break; 
    rewrite ^/tag/([^/.]+)/$ /tag.php?tag=$1 break; 
} 
+0

내/etc/nginx/sites-enabled/폴더에는 아무것도 없습니다. 비어 있습니다. 나는/etc/nginx/sites에 서버 설정을 추가했다. –

+0

당신은'ln -s /etc/sites-available/foo.com.conf/etc/sites-enabled/foo.com.conf'와 심볼릭 링크를하고'sudo nginx -s reload'를 사용하여 nginx를 다시로드 할 수 있습니다 –