sudo apt-get install nginx
service nginx start
sudo service nginx start
sudo systemctl start nginx
Nginx 관련 디렉토리 경로는 /etc/nginx이다.
기본적인 설정 파일의 경로는 /etc/nginx/conf.d 디렉토리 하위의
default.conf에 있다.
혹시나 conf.d 디렉토리 아래에 기본 설정 파일이 없다면
/etc/nginx/site-available이라는 디렉토리 하위에 있다.
conf.d, sites-enabled, sites-available 디렉토리 설정을 하는데
각각의 차이는 다음과 같다.
각 디렉토리의 용도에 따라, 디렉토리 추상화를 통해
작업을 좀 더 체계화 하고 별도의 지원 스크립트로 관리 가능하니
conf.d 디렉토리에 직접 설정하지 않고
sites-enabled과 sites-available를 사용한다.
sites-enabled 디렉토리를 Nginx 설정 파일 경로로 사용하기 위해 nginx.conf을 수정한다.
conf.d 디렉토리에 대해서는 비활성화를 위해 # 붙여 주석처리해주거나
아예 해당 라인을 지워준다.
# /etc/nginx/nginx.conf
...
#gzip on;
#include /etc/nginx/conf.d/*.conf;
// ↓ 이부분 추가
include /etc/nginx/sites-enabled/*; }
#/etc/nginx/sites-availalbe/test.conf
server {
listen 80;
server_name {localhost 혹은 도메인};
# 정적 서버 연결
location /{
root /{프로젝트 디렉토리};
index index.html index.htm;
try_files $uri $uri/ /index.html;
}
}
만약, 정적 서버가 아닌, proxy 설정으로 현재 서버에서 돌아가고 있는
애플리케이션으로 연결해주기 위해서는 아래와 같이 설정하면 된다.
#/etc/nginx/sites-availalbe/test.conf
server {
listen 80;
server_name {localhost 혹은 도메인};
#동적 서버 연결
location /{
proxy_pass http://localhost:{포트 번호};
}
}
이제 생성한 test.conf 를 sites-enabled 디렉토리에 심볼릭 링크 설정을 아래와 같이 해준다.
ln -s /etc/nginx/sites-available/test.conf /etc/nginx/sites-enabled/test.conf
변경 사항을 적용시키기 위해 아래 재실행 명령어를 입력해준다.
service nginx restart
sudo service nginx restart
sudo systemctl restart nginx
sudo nginx -t