OSX 웹서버

[macOS] Nginx 가상호스트 설정


[macOS] Nginx 가상호스트 설정


  2021-10-12  535 View 공개

nginx에 가상호스트틀 설정해보자.
호스트 도메인은 corn-sample.com이다.

기본 도큐먼트 위치 : /opt/homebrew/var/www

hosts 파일 수정

127.0.0.1 corn-sample.com
127.0.0.1 www.corn-sample.com

가상호스트 설정

가상호스트 파일은 별도의 디렉토리에 두는 것이 보기 좋으니 nginx conf 홈파일에 servers라는 디렉토리를 만들어서 nginx.conf파일에 servers 디렉토리 파일을 include하게 한다.

# /usr/local/etc/nginx/nginx.conf
http{
    ...
    include servers/*; # 가상호스트설정파일 경로 추가
}
# /usr/local/etc/nginx/servers/corn-sample.conf
server {
    listen 80;
    server_name www.corn-sample.com corn-sample.com;

    location / {
        root /usr/local/var/www/frontend;/ # vue js 경로
        index index.html;
    }

    error_page 500 502 503 504 /50x.html;
    location = /50x.html {
        root html;
    }
}

이렇게 설정한 후에 브라우저에 corn-sample.com에 접속하면 /usr/local/var/www/frontend/index.html이 정상적으로 뜨는것을 볼 수 있다.
그런데.. 문제는 127.0.0.1로 접속해도 해당 페이지가 뜬다는 것이다.
따라서 default 가상호스트를 설정해 주자

default 가상호스트 설정

# /usr/local/etx/nginx/servers/default.conf
server{
    listen 80 default;
    server_name _;

    location / {
        root /usr/local/var/www/default;
        index index.html;
    }
}

domain이 일치하지 않는 요청건은 /usr/local/var/www/default/index.html을 보여주게 된다.


Tags  #NGINX  #가상호스트  



🚩 OSX 웹서버 글 모음 (총 59 건)

[macOS] 빅서 (Big Sur) 에서 아파치 + PHP 8.X 설치하기

Last Updated : 2023-09-05
#매킨토시 #애플맥 #맥미니 #맥북

[MaxOSX] 이미 발급된 Lets Encrypt 의 SSL 인증서 삭제

Last Updated : 2023-09-05

[macOS] SSH로 접속 시도한 로그 조회하기

Last Updated : 2023-07-07

[macOS] M1 맥미니/맥북에어에 Homebrew 설치여부 확인하기

Last Updated : 2023-07-07

[macOS] M1 맥미니/맥북에어에 Apache 웹서버가 설치되어 있는지 확인하는 방법

Last Updated : 2023-07-07

[macOSX] 맥 터미널에서 디렉토리 복사 명령어

Last Updated : 2023-07-06