티스토리 뷰

Web programing/Nginx

Nginx 이해 & 기본 설정

내일도이렇게 2020. 3. 16. 21:24

 

 

 

Nginx 란 

  • 비동기 이벤트 기반 구조의 웹 서버 

  • 비동기 소켓을 사용하는 빠르고 강력한 HTTP 서버로, 아파치 웹 서버를 대체할 대안으로 급부상 

Nginx(웹서버)의 역할 

 

  •   정적 파일(이미지, css, html ) 을 처리하는 HTTP 서버로의 역할
  •   서버에 요청을 보내는 리버스 프록시로서의 역할 
     * 리버스 프록시 : 클라이언트는 가짜 서버에 요청하면, 프록시 서버(nginx) 가 배후 서버로부터 데이터를 가져오는 역할

Nginx 설치 

  •   apt-get install nginx 

Nginx 시작 & 중지 

  •  service nginx status : 상태보기 
  •  service nginx start:  시작
  •  service nginx stop : 중지
  •  service nginx restart: 재시작 
  •  

Nginx 의 디렉터리 

 

  •   /etc/nginx :  nginx를 설정하는 디텍터리 
  •   /etc/nginx/nginx.conf : 메인 설정 파일 
  •   /etc/nginx/sites-available : 비활성화된 사이트들의 설정 파일들의 위치 
  •   /etc/nginx/sites-enabled:  활성화된 사이트들의 설정 파일들의 위치       
        sites-available 디렉터리에서 연결된 파일들이 존재하는 곳 

nginx.conf 설정 

   path: /etc/nginx/nginx.conf 

user www-data;    
worker_processes auto; 
pid /run/nginx.pid;


events {
        worker_connections 768;
        # multi_accept on;
}


http {

        ##
        # Basic Settings
        ##

        sendfile on;
        tcp_nopush on;
        tcp_nodelay on;
        keepalive_timeout 65;
        
        
        access_log /var/log/nginx/access.log;
        error_log /var/log/nginx/error.log;

        ##
        # Virtual Host Configs
        ##

        include /etc/nginx/conf.d/*.conf;
        include /etc/nginx/sites-enabled/*;

}

 

1. Core 모듈 

user www-data;    
worker_processes auto; 
pid /run/nginx.pid;

 user www-data; 

  •    user 워커 프로세스의 권한을 지정
  •    NGINX 프로세스가 실행되는 권한 
  •    nginx 는 마스터 와 워커 프로세스로 나뉨. 
  •    워커 프로세스가 실질적인 웹서버 역할 

worker_process 

  •  워커 프로세스 지정, 실적적인 웹서버 역할
  •   auto 로 지정하는 경우에는 자동으로 지정. 서버에 장착되어 있는 코어 수만큼 할당하는 것이 보통이며 더 높게 설정 가능

pid:

  • NGINX 마스터 프로세스 ID 정보가 저장

 

2. events 블록

 

events {
        worker_connections 768;
        # multi_accept on;
}

worker_connections 

  • 하나의 프로세스가 처리할 수 있는 커넥션의 수
  • 최대 접속자수 = worker_processes X woker_connections 

 

3. http 블록 

http {

        keepalive_timeout 65;
        
        access_log /var/log/nginx/access.log;
        error_log /var/log/nginx/error.log;

        include /etc/nginx/conf.d/*.conf;
        include /etc/nginx/sites-enabled/*;

}

keepalive_timeout

  • 접속시 커녁션을 몇 초동안 유지할지에 대한 설정값

server_tokens off;

  •  response header 에 nginx 버전를 표시할지 정의 
  • 보안을 위해 off 

log_format 

  • 로그의 포맷을 정의

access_log

  •   로그 경로 

include

  • 가상 호스트 설정이나 반복되는 옵션 항목을 include 로 가져오기

 


Reference

  • https://wan-blog.tistory.com/54
  • https://12bme.tistory.com/366
  • https://whatisthenext.tistory.com/123

 

 

 

 

공지사항
최근에 올라온 글
최근에 달린 댓글
Total
Today
Yesterday
링크
«   2024/09   »
1 2 3 4 5 6 7
8 9 10 11 12 13 14
15 16 17 18 19 20 21
22 23 24 25 26 27 28
29 30
글 보관함