주소 리다이렉트 하는법 부탁드립니다.
본문
안녕하세요
기본 접속 주소는
입니다.
xxxxx.co.kr
등 으로 접속해도
접속 되게 하고 싶습니다.
감사합니다.ㅠㅠ
답변 1
도메인과 포트를 통합하여 접속하도록 설정하는 방법이군요.
아래는 Apache와 Nginx를 사용하는 경우 각각 설정하는 방법임.
1. Apache 설정
.htaccess 파일을 수정하거나, Apache 설정 파일에서 리다이렉트를 설정.
도메인의 루트 디렉토리에 .htaccess 파일을 생성하거나 수정하여 다음 내용을 추가:
RewriteEngine On
# www 없는 주소를 www로 리다이렉트
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteRule ^(.*)$ https://www.xxxxx.co.kr:461/$1 [L,R=301]
# http를 https로 리다이렉트
RewriteCond %{HTTPS} off
RewriteRule ^(.*)$ https://www.xxxxx.co.kr:461/$1 [L,R=301]
# 포트를 포함한 최종 주소로 리다이렉트
RewriteCond %{HTTP_HOST} ^xxxxx\.co\.kr$ [NC]
RewriteRule ^(.*)$ https://www.xxxxx.co.kr:461/$1 [L,R=301]
위 요청은 도메인과 포트를 통합하여 접속하도록 설정하는 방법으로,
웹 서버의 리다이렉트 설정을 적용해야 함.
2. Nginx 설정
Nginx 설정 파일에서 서버 블록을 이용하여 리다이렉트를 설정.
server {
listen 80;
server_name www.xxxxx.co.kr xxxxx.co.kr;
# 모든 HTTP 요청을 HTTPS로 리다이렉트
return 301 https://www.xxxxx.co.kr:461$request_uri;
}
server {
listen 443 ssl;
server_name www.xxxxx.co.kr xxxxx.co.kr;
# SSL 인증서 설정
ssl_certificate /path/to/certificate.crt;
ssl_certificate_key /path/to/private.key;
# 기본 포트와 연결
location / {
proxy_pass http://127.0.0.1:461;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
}
*위의 예시는 SSL 인증서 설정이 필요하므로,
모든 도메인(예: www.xxxxx.co.kr, xxxxx.co.kr)에 대해 SSL 인증서를 발급받아야 합니다.
*DNS A 레코드: www.xxxxx.co.kr와 xxxxx.co.kr이 동일한 서버 IP를 설정합니다.
*CNAME 레코드: www.xxxxx.co.kr이 xxxxx.co.kr을 가리키도록 설정하면
DNS 차원에서도 리다이렉트가 동작합니다.
= = = = = = = = = = = = =
리버스 프록시를 활용하시길 권장합니다.
여러 도메인과 포트로 들어오는 요청을 특정 도메인로 라우팅하세요.
★ 모든 요청이 "www.xxxxx.co.kr"로 리디렉트되는 예시입니다.
- Nginx 설정 예시
# HTTP 요청 처리
server {
listen 80;
server_name www.xxxxx.co.kr xxxxx.co.kr;
# 모든 HTTP 요청을 HTTPS로 리다이렉트
return 301 https://www.xxxxx.co.kr$request_uri;
}
# HTTPS 요청 처리
server {
listen 443 ssl;
server_name www.xxxxx.co.kr xxxxx.co.kr;
# SSL 인증서 설정
ssl_certificate /path/to/certificate.crt;
ssl_certificate_key /path/to/private.key;
# 리버스 프록시 설정
location / {
proxy_pass http://127.0.0.1:461; # 내부 서버로 요청 전달
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
}
}
- Apache 설정 예시
<VirtualHost *:80>
ServerName www.xxxxx.co.kr
ServerAlias xxxxx.co.kr
# HTTP -> HTTPS 리다이렉트
Redirect permanent / https://www.xxxxx.co.kr/
</VirtualHost>
<VirtualHost *:443>
ServerName www.xxxxx.co.kr
ServerAlias xxxxx.co.kr
# SSL 설정
SSLEngine On
SSLCertificateFile /path/to/certificate.crt
SSLCertificateKeyFile /path/to/private.key
# 리버스 프록시 설정
ProxyPreserveHost On
ProxyPass / http://127.0.0.1:461/
ProxyPassReverse / http://127.0.0.1:461/
</VirtualHost>