본문 바로가기

서버

CentOs7 - 가상서버 nginx 초반 셋팅

728x90

1. 비번 변경

passwd

 

2. 유틸 설치

yum install yum-utils

 

3. Repository 설정

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

nginx pacakge 받으려면 

텍스트로 받을 설정 해놓고 보내야함

 

[nginx-stable]
name=nginx stable repo
baseurl=http://nginx.org/packages/centos/$releasever/$basearch/
gpgcheck=1
enabled=1
gpgkey=https://nginx.org/keys/nginx_signing.key
module_hotfixes=true

[nginx-mainline]
name=nginx mainline repo
baseurl=http://nginx.org/packages/mainline/centos/$releasever/$basearch/
gpgcheck=1
enabled=0
gpgkey=https://nginx.org/keys/nginx_signing.key
module_hotfixes=true

 

4. nginx 설치

yum -y install nginx

 

5. 홈으로 사용할 디렉토리를 생성하고, 해당 디렉토리의 소유권을 설정

~# mkdir -p /ncp/data/www
~# chown -R nginx:nginx /ncp/data/www
~# cp /usr/share/nginx/html/index.html /ncp/data/www/index.html
~# ls -al /ncp/data/www

 

6. 환경설정

vi /etc/nginx/conf.d/default.conf

 

7. conf 수정

# 변경 전
    location / {
        root   /usr/share/nginx/html;
        index  index.html index.htm;
    }

# 변경 후
    root   /ncp/data/www;
    index  index.html index.htm;

    location / {
        try_files $uri $uri/ = 404;
    }

 

 

 

# 변경 전
    #error_page  404              /404.html;

    location = /50x.html {
        root   /usr/share/nginx/html;
    }

# 변경 후
    error_page  404              /404.html;

    location = /50x.html {
        root   /ncp/data/www;
    }

 

 

 

 

 

8. nginx 실행

~# systemctl start nginx
~# systemctl status nginx

 

 


오류를 만나서 자기전에 30분간 헤메었다. 

그 이유는 .. 

 

자세히 읽어보니 /50x.html 에 대한 내용이 duplicate였다.

 

밑에껄 주석처리하고 재시작하니 된다!