Linux

[Nginx] Nginx 소개, 설치, 서비스 구동 in CentOS 8

작성자 정보

  • 차태식 작성
  • 작성일

컨텐츠 정보

본문

Nginx에 대한 내용 및 설치 후, 서비스 구동을 테스트한 내용을 정리합니다.


Nginx

Nginx(엔진x)는 웹서버 소프트웨어로 가벼움과 높은 성능을 목표로 한다고 합니다.

Nginx와 유사한 웹서버 소프트웨어로는 아파치, IIS(윈도우) 등이 있고 윕서버를 구동함에 있어서 상당히 많이 사용중에 있는 웹서버 소프트웨어 입니다.


Nginx 기능

ㅇ HTTP 프록시와 웹 서버 기능

  • 정적 파일과 인덱스 파일 표현, 자동 인덱싱 기능.
  • 캐싱을 통한 리버스 프록시
  • 로드 밸런싱
  • 고장 진단
  • SSL 지원
  • 캐싱을 통한 FastCGI 지원
  • Name-, IP-기반 가상서버
  • FLV 스트리밍
  • MP4 스트리밍 모듈을 이용한 MP4 스트리밍
  • 웹페이지 접근 인증
  • gzip 압축
  • 10000개의 동시 접속을 처리할 수 있는 능력
  • URL 다시쓰기 (URL rewriting)
  • 맞춤 로깅
  • 서버 사이드 기능 포함
  • WebDAV

ㅇ 메일 프록시 기능

  • SMTP, POP3, IMAP 프록시
  • STARTTLS 지원
  • SSL 지원

테스트 환경

ㅇ CentOS 8.0

   [jackerlab@jackerlab ~]$ cat /etc/redhat-release 
CentOS Linux release 8.0.1905 (Core) 
[jackerlab@jackerlab ~]$ 
   

ㅇ 커널

   [jackerlab@jackerlab ~]$ uname -a
Linux jackerlab 4.18.0-80.11.2.el8_0.x86_64 #1 SMP Tue Sep 24 11:32:19 UTC 2019 x86_64 x86_64 x86_64 GNU/Linux
   

ㅇ Root 계정으로 진행


Nginx 설치

   [root@jackerlab ~]# dnf install nginx
   

Nginx 서비스 구동, 확인, 정지, 재시작, 설정 반영

ㅇ 서비스 구동

   [root@jackerlab ~]# systemctl start nginx
   

ㅇ 서비스 상태 확인

   [root@jackerlab ~]# systemctl status nginx
   

ㅇ 서비스 중지

   [root@jackerlab ~]# systemctl stop nginx
   

ㅇ 서비스 재시작

   [root@jackerlab ~]# systemctl restart nginx
   

ㅇ 설정 반영

   [root@jackerlab ~]# systemctl reload nginx
   

Nginx 서비스 구동 및 확인

   [root@jackerlab ~]# systemctl start nginx
[root@jackerlab ~]# systemctl status nginx
● nginx.service - The nginx HTTP and reverse proxy server
   Loaded: loaded (/usr/lib/systemd/system/nginx.service; disabled; vendor preset: disabled)
   Active: active (running) since Tue 2020-05-05 14:42:12 UTC; 7s ago
  Process: 1960 ExecStart=/usr/sbin/nginx (code=exited, status=0/SUCCESS)
  Process: 1958 ExecStartPre=/usr/sbin/nginx -t (code=exited, status=0/SUCCESS)
  Process: 1957 ExecStartPre=/usr/bin/rm -f /run/nginx.pid (code=exited, status=0/SUCCESS)
 Main PID: 1962 (nginx)
    Tasks: 2 (limit: 9584)
   Memory: 6.6M
   CGroup: /system.slice/nginx.service
           ├─1962 nginx: master process /usr/sbin/nginx
           └─1963 nginx: worker process
May 05 14:42:12 jackerlab systemd[1]: Starting The nginx HTTP and reverse proxy server...
May 05 14:42:12 jackerlab nginx[1958]: nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
May 05 14:42:12 jackerlab nginx[1958]: nginx: configuration file /etc/nginx/nginx.conf test is successful
May 05 14:42:12 jackerlab systemd[1]: nginx.service: Failed to parse PID from file /run/nginx.pid: Invalid argument
May 05 14:42:12 jackerlab systemd[1]: Started The nginx HTTP and reverse proxy server.
[root@jackerlab ~]#
[root@jackerlab ~]# netstat -nltp
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address           Foreign Address         State       PID/Program name    
tcp        0      0 0.0.0.0:22              0.0.0.0:*               LISTEN      1430/sshd              
tcp        0      0 0.0.0.0:80              0.0.0.0:*               LISTEN      1962/nginx: master  
tcp6       0      0 :::22                   :::*                    LISTEN      1430/sshd           
tcp6       0      0 :::80                   :::*                    LISTEN      1962/nginx: master  
[root@jackerlab ~]#
   

Nginx를 구동하면 정상적으로 서비스가 구동이 되는 것을 확인할 수 있고 netstat -nltp 명령어로 80 포트가 Nginx 프로세스에 의해 Listening을 하고 웹서버가 구동되고 있음을 확인할 수 있습니다.


Nginx 설정 파일

ㅇ Nginx의 설정 파일 경로

   [root@jackerlab ~]# cat /etc/nginx/nginx.conf
   

ㅇ Nginx 기본 설정 파일 내용

   [root@jackerlab ~]# cat /etc/nginx/nginx.conf
# For more information on configuration, see:
#   * Official English Documentation: http://nginx.org/en/docs/
#   * Official Russian Documentation: http://nginx.org/ru/docs/
user nginx;
worker_processes auto;
error_log /var/log/nginx/error.log;
pid /run/nginx.pid;
# Load dynamic modules. See /usr/share/doc/nginx/README.dynamic.
include /usr/share/nginx/modules/*.conf;
events {
    worker_connections 1024;
}
http {
    log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
                      '$status $body_bytes_sent "$http_referer" '
                      '"$http_user_agent" "$http_x_forwarded_for"';
    access_log  /var/log/nginx/access.log  main;
    sendfile            on;
    tcp_nopush          on;
    tcp_nodelay         on;
    keepalive_timeout   65;
    types_hash_max_size 2048;
    include             /etc/nginx/mime.types;
    default_type        application/octet-stream;
    # Load modular configuration files from the /etc/nginx/conf.d directory.
    # See http://nginx.org/en/docs/ngx_core_module.html#include
    # for more information.
    include /etc/nginx/conf.d/*.conf;
    server {
        listen       80 default_server;
        listen       [::]:80 default_server;
        server_name  _;
        root         /usr/share/nginx/html;
        # Load configuration files for the default server block.
        include /etc/nginx/default.d/*.conf;
        location / {
        }
        error_page 404 /404.html;
            location = /40x.html {
        }
        error_page 500 502 503 504 /50x.html;
            location = /50x.html {
        }
    }
# Settings for a TLS enabled server.
#
#    server {
#        listen       443 ssl http2 default_server;
#        listen       [::]:443 ssl http2 default_server;
#        server_name  _;
#        root         /usr/share/nginx/html;
#
#        ssl_certificate "/etc/pki/nginx/server.crt";
#        ssl_certificate_key "/etc/pki/nginx/private/server.key";
#        ssl_session_cache shared:SSL:1m;
#        ssl_session_timeout  10m;
#        ssl_ciphers PROFILE=SYSTEM;
#        ssl_prefer_server_ciphers on;
#
#        # Load configuration files for the default server block.
#        include /etc/nginx/default.d/*.conf;
#
#        location / {
#        }
#
#        error_page 404 /404.html;
#            location = /40x.html {
#        }
#
#        error_page 500 502 503 504 /50x.html;
#            location = /50x.html {
#        }
#    }
}
[root@jackerlab ~]#
   

Nginx 서비스 포트 추가 설정

Nginx 기본설정 파일(/etc/nginx/nginx.conf)에는 80, 443 포트에 대한 내용이 샘플로 작성되어 있습니다.

80, 443 외에 추가로 웹 서비스 포트를 구동하기 위해서는 동일한 설정 구문(sever { ~ })을 복사해서 활용하시면 되겠습니다.

다음은 8443 포트로 서비스 포트를 추가 설정하고 구동하는 내용입니다.

   [root@jackerlab ~]# vim /etc/nginx/nginx.conf
... (앞부분 생략)
    server {
        listen       8443 default_server;
        listen       [::]:8443 default_server;
        server_name  _;
        root         /usr/share/nginx/html;
        # Load configuration files for the default server block.
        include /etc/nginx/default.d/*.conf;
        location / {
        }
        error_page 404 /404.html;
            location = /40x.html {
        }
        error_page 500 502 503 504 /50x.html;
            location = /50x.html {
        }
    }
... (뒷부분 생략)
[root@jackerlab ~]# 
[root@jackerlab ~]# netstat -nltp
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address           Foreign Address         State       PID/Program name    
tcp        0      0 0.0.0.0:80              0.0.0.0:*               LISTEN      13479/nginx: worker 
tcp        0      0 0.0.0.0:22              0.0.0.0:*               LISTEN      1013/sshd           
tcp        0      0 0.0.0.0:8443            0.0.0.0:*               LISTEN      13479/nginx: worker 
tcp        0      0 0.0.0.0:443             0.0.0.0:*               LISTEN      13479/nginx: worker 
[root@jackerlab ~]#
   

80, 443, 8443 포트에 대하여 nginx 설정을 모두 했다면 위와 같이 정상적으로 서비스 포트가 구동된 것을 확인 할 수 있겠습니다.


레퍼런스

ㅇ Nginx 위키백과 : https://ko.wikipedia.org/wiki/Nginx

ㅇ Nginx 사이트 : https://www.nginx.com/

관련자료

댓글 0
등록된 댓글이 없습니다.
전체 14 / 1 페이지
RSS
  • 기억노트 : kvm image.qcow2 copy 하고…
    등록자 차태식
    등록일 09.05 조회 699

    기억노트 ls -alh qemu-img info kvm.qcow2 copy 하기 cp taget.qcow2 taget.qcow2copy size…

  • 서버 부팅 시 자동 명령어 실행 [rc.local]
    등록자 jsjs
    등록일 07.19 조회 725

    1. 스크립트 sh 파일 만들기 // server_start.sh cd /home/test.com && forever start …

  • 오류: rpmdb open failed
    등록자 dev-venom
    등록일 07.18 조회 893

    linux 오류 오류: rpmdb open failed 원인: rpm 깨짐 해결: rpm 삭제 후 다시 빌드 후 $releasever ->…

  • [Nginx] Nginx 소개, 설치, 서비스 구동 i…
    등록자 차태식
    등록일 07.11 조회 905

    Nginx에 대한 내용 및 설치 후, 서비스 구동을 테스트한 내용을 정리합니다. Nginx Nginx(엔진x)는 웹서버 소프트웨어로 가벼움과 높…

  • Nginx 웹 서버 설치
    등록자 차태식
    등록일 07.11 조회 717

    Nginx 웹 서버 설치 1)업데이트 sudo dnf update 2) nginx 검색 및 버전 확인 sudo dnf list install n…

  • Linux : CentOS 8 : Nginx 설치 방법…
    등록자 차태식
    등록일 07.11 조회 741

    필수 조건 계속하기 전에 sudo 권한이 있는 사용자로 로그인하고 포트 80 또는 443에서 실행 중인 Apache 또는 다른 프로세스가 없는지…

  • Nginx 구조와 파일 소개: 웹 서버 관리의 핵심
    등록자 차태식
    등록일 07.11 조회 834

    엔진엑스(Nginx)는 Apache와 비교하여 우수한 성능과 뛰어난 동작의 간결함을 제공하는 웹 서버 프로그램이다. 주로 전달자 역할에 특화되어…

  • Dell 시스템에서 하드웨어 가상화를 활성화 또는 비활…
    등록자 차태식
    등록일 07.10 조회 599

    Dell 시스템에서 하드웨어 가상화를 활성화 또는 비활성화합니다. 시스템전원을 켭니다. Dell 로고가 표시되면F2키를 눌러 BIOS 설정으로 …

  • CentOS 8에서 사용하지 않는 오래된 커널을 삭제하…
    등록자 차태식
    등록일 07.04 조회 831

    커널은 소프트웨어와 하드웨어 사이의 다리이며 하드웨어와 상호 작용하는 운영 체제의 일부입니다. 정상적인 상황에서 설치된 커널의 수는 시스템의 성…

  • nvidia 그래픽 카드가 없는 RHEL 8 에서 가상… 댓글 1
    등록자 차태식
    등록일 05.14 조회 967

    nvidia 그래픽 카드가 없는 RHEL 8에서 가상 모니터설정 1. yum install xorg-x11-drv-dummy 2. vi /etc…

  • 스토리지 Mount 하기
    등록자 차태식
    등록일 05.11 조회 859

    1. 하드디스크 추가 - /dev/sdb 가 보이면 정상. 2. 파티션 생성 $ fdisk /dev/sdb1 = fdisk (마운트할 디스크 경…

  • xfs 로 디스크 생성하기
    등록자 freeman
    등록일 05.11 조회 728

    디스크 추가 -- insert disk -- fdisk /dev/sda n p 1 [enter] [enter] y w mkfs.xfs /dev/…

  • CentOS 부팅후 root 자동로그인 설정
    등록자 차태식
    등록일 02.02 조회 962

    CentOS 에서 부팅 후 root로 자동로그인 안될 시 서비스가 올라오지 않기때문에 수동으로 직접 로그인을 해줘야 합니다. 설정 방법 1. v…

  • Rocky Linux EL9 또는 EL8에 Google…
    등록자 차태식
    등록일 02.02 조회 1855

    Rocky Linux EL9 또는 EL8에 Chrome을 설치하는 방법 마지막 업데이트2023 년 12 월 4 일 월요일조슈아 제임스 기술 거대…