728x90
반응형

Nginx 웹서버 설치 방법

Django 웹서버에 배포 하기 위해 Nginx 설치방법에 대해 알아 보겠습니다. 

1.Nginx 저장소 추가

/etc/yum.repos.d/ 경로에 nginx 레파지 토리 추가 합니다. 

 

$ cd /etc/yum.repos.d/
$ vi   nginx.repo
[nginx]
name=nginx repo
baseurl=http://nginx.org/packages/centos/7/$basearch/
gpgcheck=0
enabled=1

 

2. 설치

 yum install -y nginx

 

3.Nginx 설정 파일 수정 

Nginx 설정 관련한 파일을 수정합니다. 

  • /etc/nginx/conf.d/default.conf 
  • nginx 에서 사용할 포트를 수정합니다. 사용하고자 하는 포트를 정해서 변경해주세요 
  • 저는 80 -> 8088 포트를 사용하겠습니다.
server {
    listen       8088;
    server_name  localhost;

    #access_log  /var/log/nginx/host.access.log  main;

    location / {
        root   /usr/share/nginx/html;
        index  index.html index.htm;
    }

    #error_page  404              /404.html;

    # redirect server error pages to the static page /50x.html
    #
    error_page   500 502 503 504  /50x.html;
    location = /50x.html {
        root   /usr/share/nginx/html;
    }

    # proxy the PHP scripts to Apache listening on 127.0.0.1:80
    #
    #location ~ \.php$ {
    #    proxy_pass   http://127.0.0.1;
    #}

    # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
    #
    #location ~ \.php$ {
    #    root           html;
    #    fastcgi_pass   127.0.0.1:9000;
    #    fastcgi_index  index.php;
    #    fastcgi_param  SCRIPT_FILENAME  /scripts$fastcgi_script_name;
    #    include        fastcgi_params;
    #}

    # deny access to .htaccess files, if Apache's document root
    # concurs with nginx's one
    #
    #location ~ /\.ht {
    #    deny  all;
    #}
}

4. 방화벽 설정

Nginx 포트 방화벽 해제를 합니다. 

테스트를 위해 방화벽을 중지 시켰습니다.

보안이 걱정 된다면 방화벽 활성화 이후 Nginx 리스너 포트를 개방해 주세요 

$ firewall-cmd --state       
running
# 방확벽 중지 
systemctl stop firewalld

# 방확벽 시작 
systemctl start  firewalld

# 방화벽 상태 확인 
firewall-cmd --state

# 포트 개방
firewall-cmd --permanent --zone=public --add-port=8088/tcp

# 방화벽 재시작
firewall-cmd --reload

# 개방된 포트 목록 확인
firewall-cmd --list-ports

5. Nginx 서비스 시작

#nginx 서비스 활성화
systemctl enable nginx

#Nginx 서비스 시작 
systemctl start nginx

#Nginx 서비스 상태 확인
systemctl status nginx
  • nginx 서비스 상태 확인

$ systemctl status nginx
* nginx.service - nginx - high performance web server
   Loaded: loaded (/usr/lib/systemd/system/nginx.service; enabled; vendor preset: disabled)
   Active: active (running) since 금 2022-04-08 11:21:58 KST; 1min 9s ago
     Docs: http://nginx.org/en/docs/
  Process: 23340 ExecStart=/usr/sbin/nginx -c /etc/nginx/nginx.conf (code=exited, status=0/SUCCESS)
 Main PID: 23341 (nginx)
    Tasks: 5
   Memory: 3.2M
   CGroup: /system.slice/nginx.service
           |-23341 nginx: master process /usr/sbin/nginx -c /etc/nginx/nginx.conf
           |-23342 nginx: worker process
           |-23343 nginx: worker process
           |-23344 nginx: worker process
           `-23345 nginx: worker process

6. Nginx  웹페이지 접속 

http://localhost:8088/ 로 접속 해서 정상 적으로 설치 되었는지 확인 합니다.

Nginx  접속

728x90
반응형

+ Recent posts