[CentOS 7] CentOS 7 - NGINX 설치 방법

728x90
반응형

CentOS 7  버전에 Nginx 설치 방법 정리

 

 

요약

  1. yum 외부 저장소 추가
  2. yum install
  3. 방화벽 포트 개방
  4. nginx 포트 설정
  5. nginx 데몬 실행
  6. 실행

1. yum 외부 저장소 추가

yum  저장소에는 nginx가 없기 때문에 외부 저장소를 추가 해야 하며, 

[root@localhost /]# cd etc/yum.repos.d/
[root@localhost yum.repos.d]# ls
CentOS-Base.repo  CentOS-CR.repo  CentOS-Debuginfo.repo  CentOS-Media.repo  CentOS-Sources.repo  CentOS-Vault.repo  CentOS-fasttrack.repo  microsoft-prod.repo
[root@localhost yum.repos.d]# vi nginx.repo
[root@localhost yum.repos.d]#

 

/etc/yum.repos.d/ 경로에 nginx.repo 파일을 추가하고 아래와 같이 작성해줍니다. 

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

위 내용은 공식 사이트에 있으며, OS가 다르다면 해당 OS에 맞게 수정해 주면 됩니다. 

 


 

2. yum install

yum install 명령어를 이용해서 설치해 줍니다. 

[root@localhost ~]# yum install -y nginx

 

 


 

3. 방화벽 포트 개방

[root@localhost ~]#
[root@localhost ~]#
[root@localhost ~]# firewall-cmd --permanent --zone=public --add-port=8089/tcp
success
[root@localhost ~]# firewall-cmd --reload
success
[root@localhost ~]# firewall-cmd --list-ports
21/tcp 5000/tcp 5001/tcp 8089/tcp
[root@localhost ~]#

 


 

4. Nginx 포트 설정

[root@localhost ~]# vi /etc/nginx/conf.d/default.conf


server {
    listen       8080;
    server_name  localhost;

    #charset koi8-r;
    #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;
    #}
}

 


 

5. Nginx 데몬 실행

[root@localhost ~]# systemctl start nginx
[root@localhost ~]# systemctl enable nginx
Created symlink from /etc/systemd/system/multi-user.target.wants/nginx.service to /usr/lib/systemd/system/nginx.service.

 


 

6. 실행화면

정상적으로 데몬이 실행되었다면, http://localhost:8080 접속시 아래와 같은 페이지가 보여집니다. 

 

 

 


 

 

https://cofs.tistory.com/412

 

CentOS7 Nginx 설치 방법

CentOS7 에 Nginx 설치 방법에 대해서 설명한다. yum을 활용하여 쉽게 설치해 보자. 요약 yum 외부 저장소 추가 yum install 방화벽 포트 개방 nginx 포트 설정 nginx 데몬 실행 데몬 실행시 오류 발생 (오류 ��

cofs.tistory.com

 

728x90