1. 일반 redirect

server { 

    listen       80; 

    server_name  redirect.test.co.kr; 

    return       301  

    http://www.redirect.test.co.kr$request_uri; 

 

server { 

    listen       80; 

    server_name  www.redirect.test.co.kr; 

    location / { 

        root   /usr/share/nginx/html; 

        index  index.html index.htm; 

    } 


server { 

    listen       80; 

    server_name  oldsite.test.co.kr; 

    return       301 http://newsite.test.co.kr$request_uri; 

 

server { 

    listen       80; 

    server_name  newsite.test.co.kr; 

    location / { 

        root   /usr/share/nginx/html; 

        index  index.html index.htm; 

    } 


2. ssl로 redirect


server { 

    listen 80; 

    server_name ssl.test.co.kr; 

    return 301 https://ssl.nginxcookbook.com$request_uri; 

 

server { 

    listen              443 ssl; 

    server_name         ssl.test.co.kr; 

    ssl_certificate     /etc/ssl/public.pem; 

    ssl_certificate_key /etc/ssl/private.key; 

    ssl_protocols       TLSv1 TLSv1.1 TLSv1.2; 

    ssl_ciphers         HIGH:!aNULL:!MD5; 

 

    access_log  /var/log/nginx/ssl-access.log  combined; 

 

    location / { 

        root   /var/www; 

        index  index.html index.htm; 

    } 


3. single page redirect


rewrite ^/test/$  /test1/  redirect;

rewrite ^/test/?$  /test1/  redirect;



4. full directory redirect


rewrite ^/test/?(.*)$   /test1/$1  redirect;



5. PCRE (Perl Compatible Regular Expression)


$

.

\d

\D

\w

*

+

?

()


6. 404 redirect


server { 

    listen       80; 

    server_name  d.test.co.kr; 

 

    access_log  /var/log/nginx/demosite.access.log  combined; 

    index index.php; 

 

    root   /var/www/vhosts/demosite; 

 

    error_page 404 @404page; 

 

    location @404page { 

        try_files $uri $uri/ /search.php?uri=$uri&$args; 

    } 

 

    location ~ \.php$ { 

        fastcgi_pass unix:/var/run/test.sock; 

        fastcgi_index index.php; 

        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; 

        include fastcgi_params; 

 

        try_files $uri $uri/ /search.php?uri=$uri&$args; 

    } 




'오픈소스 > nginx' 카테고리의 다른 글

nginx proxy setup  (0) 2018.02.05
blocking setup for nginx  (0) 2018.02.02
logstash for nginx  (0) 2018.02.02
nginx log format 정의  (0) 2018.02.02
nginx for syslog  (0) 2018.02.02

+ Recent posts