2017년 1월 10일 화요일

NGINX 설치 및 간단한 사용법

AWS EC2를 Amazon Linux AMI로 생성한 후 NGINX를 설치할 때의 방법 및 환경에 대해 정리한 내용임.

설치환경: AWS EC2 + Amazon Linux AMI

설치 방법 (참고: https://nginx.org/en/linux_packages.html)

1. Repository 설정
/etc/yum.repos.d/nginx.repo 파일에 다음과 같이 설정

[nginx]
name=nginx repo
baseurl=http://nginx.org/packages/mainline/OS/OSRELEASE/$basearch/
gpgcheck=0
enabled=1
baseurl 중 OS는 rhel, OSRELEASE는 7로 설정함.

2. 설치
sudo yum install nginx

3. 실행
nginx

4. 컨트롤 명령
nginx -s [stop|quit|reload|reopen]
  • stop: fast shutdown
  • quit: graceful shutdown
  • reload: 설정 파일을 다시 로딩
  • reopen: 로그 파일을 다시 열기


5. ROOT 경로
/usr/share/nginx/html

6. 로그 파일 경로
/var/log/nginx/access.log

7. 설정 파일 변경
설정 파일 위치: /etc/nginx/nginx.conf
https://nginx.org/en/docs/beginners_guide.html 참고
http://kwonnam.pe.kr/wiki/nginx/location


* 아래와 같이 path와 파일명의 앞과 일치하는 경우 계속 redirection 하다가 오류가 나는 현상이 있음.
    location /send {
        # return 302 /sender.html;
        rewrite .* /sender.html;
    }

* HTTP를 HTTPS로 전환하려면, 다음과 같이 수정
    server {
        listen       80 default_server;
        listen       [::]:80 default_server;
        server_name  localhost;
        return 301 https://$host$request_uri;
    }

https://www.bjornjohansen.no/redirect-to-https-with-nginx 참고함.



저작자: Yes, 상업적 이용: No, 컨텐츠 변경: No

댓글 없음:

댓글 쓰기