[WEB] Nginx 설치하기(on Centos7)

 

1. 사전 작업

 

Nginx를 설치하기 전에 selinux와 firewalld(방화벽)을 비활성화를 시켰습니다.

[root@test-1 ~]# getenforce
Disabled
[root@test-1 ~]# systemctl stop firewalld
[root@test-1 ~]# iptables -L
Chain INPUT (policy ACCEPT)
target     prot opt source               destination         

Chain FORWARD (policy ACCEPT)
target     prot opt source               destination         

Chain OUTPUT (policy ACCEPT)
target     prot opt source               destination

 

 

2. Nginx repo 추가

 

yum으로 nginx 설치하려고하니 저장소에서 못 찼네요.

[root@test-1 ~]# yum install nginx
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
 * base: mirror.navercorp.com
 * extras: mirror.navercorp.com
 * updates: mirror.kakao.com
No package nginx available.

 

외부 공식 Nginx repo를 추가해줍니다.

repo 내용은 아래 링크를 참고했습니다.

[root@test-1 ~]# cat /etc/yum.repos.d/nginx.repo 
[nginx]
name=nginx repo
baseurl=https://nginx.org/packages/centos/$releasever/$basearch/
gpgcheck=0
enabled=1

 

repo 내용은 아래 링크를 참고했습니다.

www.nginx.com/resources/wiki/start/topics/tutorials/install/

 

 

3. Nginx 설치 및 확인

 

다시 yum을 통해 nginx을 설치합니다

[root@test-1 ~]# yum install nginx -y

 

설치 확인

[root@test-1 ~]# rpm -qa | grep nginx
nginx-1.18.0-2.el7.ngx.x86_64

 

 

4. Nginx 설정 확인

 

[root@test-1 ~]# cat /etc/nginx/nginx.conf 

user  nginx;
worker_processes  1;  # 작업 프로세스 개수

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


events {
    worker_connections  1024;  # worker process당 동시 접속 수
}


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;

    keepalive_timeout  65; # 접속된 연결을 65초가 유지

    #gzip  on;

    include /etc/nginx/conf.d/*.conf;
}

 

 

5. Nginx 구동 방법

 

구동/중단/재구동

[root@test-1 ~]# systemctl start nginx
[root@test-1 ~]# systemctl stop nginx
[root@test-1 ~]# systemctl restart nginx

 

상태 확인

[root@test-1 ~]# systemctl status nginx
● nginx.service - nginx - high performance web server
   Loaded: loaded (/usr/lib/systemd/system/nginx.service; disabled; vendor preset: disabled)
   Active: active (running) since 금 2020-12-18 18:09:02 KST; 1s ago
     Docs: http://nginx.org/en/docs/
  Process: 1607 ExecStart=/usr/sbin/nginx -c /etc/nginx/nginx.conf (code=exited, status=0/SUCCESS)
 Main PID: 1608 (nginx)
   CGroup: /system.slice/nginx.service
           ├─1608 nginx: master process /usr/sbin/nginx -c /etc/nginx/nginx.conf
           └─1609 nginx: worker process

12월 18 18:09:02 test-1 systemd[1]: Starting nginx - high performance web server...
12월 18 18:09:02 test-1 systemd[1]: Started nginx - high performance web server.

 

부팅 시 재구동 설정

[root@test-1 ~]# ip addr | grep 192
    inet 192.168.219.100/24 brd 192.168.219.255 scope global noprefixroute dynamic enp0s8

 

 

 

6. 접속 테스트

 

IP 확인

[root@test-1 ~]# ip addr | grep -i inet 
    inet 192.168.219.100/24 brd 192.168.219.255 scope global noprefixroute dynamic enp0s8

 

접속 확인!!!

댓글

Designed by JB FACTORY

loading