nginx rewirte, redirect 주소변환 설정모음
nginx 에서 주소변경
nginx 에서 주소변환
# domain.com 으로 접속 시 newdomain.com 으로 리다이렉토
server {
server_name domain.com;
return 301 http://www.newdomain.com$request_uri;
}
# domain.com/change/view.php?no=1000 으로 접속 시 domain.com/changed/article.php?art_no=1000 으로 변환
server {
server_name domain.com;
location ~* ^/change/(.*)$ {
rewrite ^/change/(.*)$ http://domain.com/changed/$1 permanent;
break;
}
# domain.com/~~~ 으로 접속 시 newdomain.com/~~~ 으로 변환
server {
server_name domain.com;
location ~* ^(.*)$ {
rewrite ^(.*)$ http://www.newdomain.com$1 permanent;
break;
}
# domain.com/aaa.html 혹은 domain.com/bbb.html 으로 접속 시 domain.com/chage.html 으로 변환
server {
server_name domain.com;
location ~* ^(.*)$ {
rewrite ^/aaa.html$ /chage.html permanent;
rewrite ^/bbb.html$ /chage.html permanent;
break;
}
# 참고할 사이트
https://www.digitalocean.com/community/tutorials/how-to-create-temporary-and-permanent-redirects-with-nginx
https://bjornjohansen.no/nginx-redirect