서브 도메인 : 기본 도메인에 호스트 이름만 다르게 붙여서 사용하는 여러 개의 도메인
- test와 product 호스트로 서브도메인 설정하기
test에는 html 파일 작성
product에는 php 파일 작성
>> 서브도메인에 따라 동일한 서버 내에서 각각 다른 파일로 접근 가능
서브 도메인 설정
1. 가비아 DNS 설정
타입 : CNAME
호스트는 각각 test, product
값/위치에 도메인주소. 를 입력한다. ( parkchanho.shop. )
-CNAME 타입 레코드
Canonical Name record의 줄임말로, 소유한 도메인에 별칭을 지정해주는 값이다.
고유한 호스트명과 레코드 값을 가지므로 도메인 소유권 확인에 이용되기도 한다.
2. Nginx 설정 파일 수정
cd /var/www/html
sudo mkdir test
sudo vi test.html
sudo mkdir product
sudo vi product.php
nginx 루트 경로에 접근한 뒤 해당 경로에 서브도메인 디렉토리를 생성한 뒤 각각의 서브도메인에 보여줄 php 혹은 html 파일을 생성한다.
test 에는 html 파일
product 에는 php 파일을 작성하였다.
2-2. Nginx 설정 변경
sudo vi /etc/nginx/sites-enabled/default
nginx 설정 파일을 vi 편집기로 수정
서브 도메인 server 추가
server {
root /var/www/html/test;
index index.html index.htm index.ngnix-debian.html test.html;
server\_name test.parkchanho.shop;
location ~ \.php$ {
include snippets/fastcgi-php.conf;
fastcgi_pass unix:/run/php/php7.2-fpm.sock;
}
location / {
try_files $uri $uri/ =404;
}
}
server {
root /var/www/html/product;
index index.php index.htm index.ngnix-debian.html product.php;
server\_name product.parkchanho.shop;
location ~ \.php$ {
include snippets/fastcgi-php.conf;
fastcgi_pass unix:/run/php/php7.2-fpm.sock;
}
location / {
try_files $uri $uri/ =404;
}
}
적용을 위해 재시작
sudo service nginx restart
+) 서브도메인에도 https 적용
Redirection 적용 (IP to Domain)
ip 주소로 접근하면 domain으로 redirection할 수 있도록 하는 설정
nginx 설정 파일로 이동
sudo vi /etc/nginx/sites-available/default
Redirection 설정
server {
listen 80;
server_name 52.78.151.1;
return 301 https://www.parkchanho.shop$request_uri;
}
적용을 위해 재시작
sudo service nginx restart
Welcome to nginx!
Welcome to nginx! If you see this page, the nginx web server is successfully installed and working. Further configuration is required. For online documentation and support please refer to nginx.org. Commercial support is available at nginx.com. Thank you f
www.parkchanho.shop
IP 주소로 접속해도 도메인 주소로 접속
최종확인
https://test.parkchanho.shop/
test.parkchanho.shop
http://product.parkchanho.shop
phpinfo()
Classes AppendIterator, ArrayIterator, ArrayObject, BadFunctionCallException, BadMethodCallException, CachingIterator, CallbackFilterIterator, DirectoryIterator, DomainException, EmptyIterator, FilesystemIterator, FilterIterator, GlobIterator, InfiniteIter
product.parkchanho.shop
- 실수 : 파일 위치 실수
test.html 파일과 product.php 파일을 작성할 때 /var/www/html 위치에 만들어서 서브 도메인 주소로 접속 시
403 forbidden error가 뜸
각 파일을 /var/www/html/test , /var/www/html/product 위치로 옮겨서 해결
'기타 > 기타' 카테고리의 다른 글
Non Functional Testing, node.js 환경에서 실습 with "Artillery" (0) | 2022.05.17 |
---|---|
Node.js 기본 개념 및 동작 원리 (0) | 2021.09.26 |
도메인 설정 및 HTTPS 적용 (0) | 2021.07.04 |
MySQL 외부 접속 허용 및 phpMyAdmin 설치 (0) | 2021.07.04 |
Window에 Local 서버 구축 및 외부 접속을 위한 Port forwarding (0) | 2021.06.29 |