Nginx에서 가상호스트 이용하기 위해서는 /etc/nginx/nginx.conf 하단의 # Virtual Host Configs 블럭에 가상호스트 설정을 추가하면 된다. 하지만 이러면 가독성도 떨어지고 설정파일이 지저분해진다는 문제가 있으므로 이렇게 하진 않는다.
# Virtual Host Configs 블럭에는 include /etc/nginx/sites-enabled/*; 라는 내용이 있는데 이것이 가상호스트 설정파일을 외부에 따로 작성하여 nginx.conf에서 불러오기 위한 설정이다.
일반적으로는 가상호스트용 설정파일은 /etc/nginx/sites-available/에 작성한 뒤 /etc/nginx/sites-enabled/에 심볼릭링크를 작성하여 불러오는 방식을 사용한다.
*가상호스트 설정
test.com 이라는 도메인을 구입해 사용하고 있다고 가정한다.
도메인관리 사이트에서 작성하고 싶은 가상호스트의 도메인인 abc.test.com을 서버의 IP에 A레코드로 연결시킨다. 서버가 요청을 받았을 때 응답해줄 디렉토리는 /var/www/html/test/라 한다.
* 다음과 같이 파일을 작성한다.
$sudo nano /etc/nginx/sites-available/abc.test.com
server { listen 80; listen [::]:80; server_name abc.test.com; root /var/www/html/test; index index.htm index.html index.php; location / { try_files $uri $uri/ =404; } location ~ \.php$ { include snippets/fastcgi-php.conf; fastcgi_pass unix:/var/run/php/php7.0-fpm.sock; } }
* sites-enabled에 심볼릭링크를 작성한다.
$ sudo ln -s /etc/nginx/sites-available/abc.test.com /etc/nginx/sites-enabled/abc.test.com
* 설정파일을 검사한 후, Nginx를 재시작한다
$ sudo nginx -t
$ sudo systemctl restart nginx
<개발 / Linux> 글갈래의 다른 글
- [Raspberry Pi] 라즈베리파이에 Taiga.io 설치하기 2019/11/20
- [Raspberry Pi] gitea 설치하기 2019/09/10
- [Raspberry Pi] Let's encrypt로 SSL인증서 취득후 Nginx 서버 HTTPS 설정 2019/04/12
- [Raspberry Pi] Nginx 가상호스트 설정하기 2019/04/11
- [Raspberry Pi] SD카드 제거없이 백업 2019/04/09
- [Raspberry Pi] SD카드 없이 USB 장치로 부팅 2019/04/09
- [Linux] Filesystem Hierarchy Standard (FHS) 2019/04/09
- [Raspberry Pi] LEMP 셋업후 워드프레스 설치 2019/04/09
- [Raspberry Pi] 한글환경 셋업 2019/04/09
- [Raspberry Pi] 방화벽 설정 2019/04/09
Comment on this post!