본문 바로가기
Devops

AWS EC2 서버에 Nginx 설치하기

by heekng 2023. 11. 5.
반응형

AWS EC2 서버에 Nginx 설치하기

지금까지 수십번 새 서버를 구축하면서 Nginx를 설치하는 과정을 매번 검색하는게 번거로워 정리합니다.

Nginx 설치 및 설정

yum update

패키지매니저를 업데이트 합니다.

yum info nginx

nginx 패키지 정보를 체크합니다. (여기서 없다고 나오는게 정상입니다.)

sudo vi /etc/yum.repos.d/nginx.repo

nginx.repo

[nginx]
name=nginx repo
baseurl=http://nginx.org/packages/centos/7/$basearch/
gpgcheck=0
enabled=1

yum에서 조회하는 레포에 nginx레포를 추가합니다.

sudo yum install nginx -y

nginx를 설치합니다.

sudo service nginx start
sudo service nginx status

Nginx 시작 및 상태를 조회합니다.

sudo service nginx reload

nginx 설정을 변경하였다면 nginx의 설정을 다시 로드합니다.
실제로 체감되지 않을 정도로 짧은 시간 내에 리로드됩니다.

(선택) conf.d 디렉토리 변경

경우에 따라 nginx의 conf 파일의 디렉토리를 사용하기 편한 디렉토리로 변경해야할 수 있습니다.

nginx 설정 참고

/etc/nginx/nginx.conf

user  nginx;
worker_processes  auto;

error_log  /var/log/nginx/error.log notice;
pid        /var/run/nginx.pid;


events {
    worker_connections  1024;
}


http {
    include       /etc/nginx/mime.types;
    default_type  application/octet-stream;

    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;

    #gzip  on;

    #    include /etc/nginx/conf.d/*.conf;
    include /[myCustomDir]/*.conf;
}

주로 사용하는 기본 설정 세팅입니다.
include /[myCustomDir]/*.conf; 부분이 내가 사용하려는 conf 파일의 위치입니다.
변경 후 nginx 리로드가 필요합니다.

반응형