본문 바로가기

ETC

nginx / 기본 라우팅 설정 방법 (conf 파일 경로 지정 방법)

 

nginx 웹서버 라우팅 설정


내가 만든 프로젝트에 도메인을 붙이고, 포트를 지정하고.. 

그 도메인으로 들어왔을때 해당서버에 있는 프로젝트 중 어떤게 root가 되는지 지정하는 방법

 

 

1. 서버에서 conf.d 폴더까지 이동

 

cd etc/nginx/conf.d 

 

이동 후, 해당 conf 파일의 이름은 상관이 없다. 프로젝트로 구분짓기 위함

그 안에 listen, server_name, root가 중요.

 

ex)

-rw-r--r-- 1 root root 1212 Dec 14  2020 콘프명.conf
-rw-r--r-- 1 root root 1220 Nov  4  2020 콘프명2.conf
-rw-r--r-- 1 root root 1225 Feb 19 10:22 콘프명3.conf
-rw-r--r-- 1 root root 1248 Apr 12 14:47 콘프명4.conf

 

 

 

 

 

2. listen port 지정(기본 포트는 80/ 원래 도메인 뒤에는 다 80이 붙어있는것

 

server {
	listen       80;
    ..
    ..
}

 

 

 

 

3. server_name 설정

 

server {
	listen       80;
    server_name  도메인주소명;
    ..
}

 

 

 

 

4. root 지정

(해당 도메인, 포트로 들어왔을때 연결한 프로젝트의 위치가 어디인지)

 

server {
	listen       80;
    server_name  도메인주소명;
    root   /home/project/프로젝트명/public;

    ..
}

 

 

 

 

5. conf 파일 수정 후 

 

nginx -t   
systemctl restart nginx

 

 

nginx-t

conf 파일 수정 후, nginx 에 문제가 없는지 확인. 아래 내용뜨면 성공.

nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
ginx: configuration file /etc/nginx/nginx.conf test is successful

 

systemctl restart nginx

nginx 재시작

반응형