레이블이 [IT] Nginx인 게시물을 표시합니다. 모든 게시물 표시
레이블이 [IT] Nginx인 게시물을 표시합니다. 모든 게시물 표시

2015년 1월 6일 화요일

Nginx + SSL 서버 구축하기

ssl 인증서버를 nginx와 연동시키는 방법입니다.
기본적으로 nginx와 ssl module이 설치되어 있어야 합니다.

구축 순서는 SSL 인증키 만들기 -> nginx에 적용시키기 순으로 이어집니다.


SSL 인증서 만들기


1. 개인키(.key)와 인증서 서명 요청 파일을 생성합니다.

# openssl req -new -newkey rsa:2048 -nodes -keyout <파일명>.key -out <파일명>.csr

Generating a 2048 bit RSA private key
...+++
.............................................+++
writing new private key to '<파일명>.key'
-----
You are about to be asked to enter information that will be incorporated
into your certificate request.
What you are about to enter is what is called a Distinguished Name or a DN.
There are quite a few fields but you can leave some blank
For some fields there will be a default value,
If you enter '.', the field will be left blank.
-----
Country Name (2 letter code) [XX]:kr
State or Province Name (full name) []:korea
Locality Name (eg, city) [Default City]:seoul
Organization Name (eg, company) [Default Company Ltd]:jun's company
Organizational Unit Name (eg, section) []:infra team
Common Name (eg, your name or your server's hostname) []:jun
Email Address []:<이메일>

Please enter the following 'extra' attributes
to be sent with your certificate request
A challenge password []:비밀번호
An optional company name []:비밀번호

주황색으로 된 부분만 알맞게 입력하시면 됩니다.

2. 파일 확인하기

# ls -al

-rw-r--r--  1 root root  1098 Jan  6 20:46 <파일명>.csr
-rw-r--r--  1 root root  1704 Jan  6 20:46 <파일명>.key

3. 자체 서명된 SSL 인증서 생성하기

# openssl x509 -req -days 365 -in <파일명>.csr -signkey <파일명>.key -out <파일명>.crt

4. password phase 삭제하기

# cp <파일명>.key <파일명>.key.secure
# openssl rsa -in <파일명>.key.secure -out <파일명>.key


nginx에 등록하기


1. nginx.conf 편집하기

# vi /usr/local/nginx/conf/nginx.conf 

HTTPS 섹션을 찾아서 변경해주세요.

 # HTTPS server
    #
    server {
        listen       443;
        server_name  localhost;
        
        ssl     on;
        ssl_certificate /root/192.168.137.61.crt;
        ssl_certificate_key     /root/192.168.137.61.key;
        ssl_session_timeout  5m;
        ssl_protocols SSLv2 SSLv3 TLSv1;
        ssl_ciphers ALL:!ADH:!EXPORT56:RC4+RSA:+HIGH:+MEDIUM:+LOW:+SSLv2:+EXP;
        ssl_prefer_server_ciphers   on;
    
        location / {
            root   <홈페이지 경로 예) /home/jun>;
            index  index.php index.html;  // html을 이용한다면 제일 첫 부분에 html로 변경
        }
    }

2. nginx에 ssl 모듈 있는지 확인하기

# /usr/local/nginx/sbin/nginx -V
nginx version: nginx/1.7.7
built by gcc 4.4.7 20120313 (Red Hat 4.4.7-11) (GCC)
TLS SNI support enabled
configure arguments: --prefix=/usr/local/nginx --with-http_ssl_module  // ssl_module 유무 확인

3. ssl 모듈 없으면 nginx 컴파일링하기

# ./configure --prefix=/usr/local/nginx --with-http_ssl_module

# make && make install

4. 설정 오류 검사하기

# /etc/init.d/nginx configtest
nginx: the configuration file /usr/local/nginx/conf/nginx.conf syntax is ok
nginx: configuration file /usr/local/nginx/conf/nginx.conf test is successful

4-1. http로 접속 했을 경우에 https로 리다이렉션하기

# vi /etc/init.d/nginx

server {
        listen       80;
        server_name  192.168.137.61;
        rewrite ^(.*) https://192.168.137.61$1 permanent; // 이 줄을 추가하면 http://192.168.137.61로 접속하면 https로 바뀌어서 접속됩니다.

5. 재시작하고 확인

# /etc/init.d/nginx restart

웹 브라우저에서 http://홈페이지 주소


2014년 12월 6일 토요일

[웹서버 설치하기] CentOS에 NginX 설치하기

Nginx란?

Nginx(엔진 x라 읽는다)는 웹 서버 소프트웨어로, 가벼움과 높은 성능을 목표로 한다. 웹 서버, 리버스 프록시 및 메일 프록시 기능을 가진다.

Netcraft의 2011년 1월 웹서버 설문조사에 따르면, nginx는 전체 도메인에서 4번째(7.50%)로 많이 쓰이는 웹서버이며, 활성화된 웹 사이트에 대한 통계에서도 역시 4번째(8.23%)로 많이 사용된다[1].

Nginx는 요청에 응답하기 위해 비동기 이벤트 기반 구조를 가진다. 이것은 아파치 HTTP 서버의 스레드/프로세스 기반 구조를 가지는 것과는 대조적이다. 이러한 구조는 서버에 많은 부하가 생길 경우의 성능을 예측하기 쉽게 해준다.


출처: http://ko.wikipedia.org/wiki/Nginx
  •  Nginx는 apache에 비해서 월등한 성능을 발휘한다는 특징이 있는데요. 특히 그림이 많은 웹서버에서 더 발군의 능력을 뽐낸다고 하네요.

Nginx 설치하기

저는 CentOS 6.5에 Nginx 1.7.8을 설치하기로 했습니다.

/usr/local/src에 다운을 받아 설치하겠습니다.

#cd /usr/local/src

#wget http://nginx.org/download/nginx-1.7.8.tar.gz

#tar zxvf nginx-1.7.8.tar.gz

#cd nginx-1.7.8

2014년 11월 27일 목요일

nginx에서 동영상 스트리밍 서비스하기

nginx에서 동영상 스트리밍이 되게 하는 방법

nginx에서는 모듈을 추가하면 웹 상에서 동영상을 바로 볼 수가 있습니다.


  1. nginx 동영상 스트리밍 모듈 설치하기
    #/usr/local/nginx/sbin/nginx -V  // nginx의 설치 경로의 sbin 디렉토리에 가면 nginx 파일이 있습니다. -V는 설치 시 옵션 보기

    1.1 확인 후 마지막 부분의 --with-http_mp4_module이 없는 분들을 위해
    #cd /usr/local/src/(nginx 압축 해제 경로)

    #./configure (기존의 설치 옵션 붙여넣기 후 맨 뒤에 mp4 모듈 옵션 추가) --with-http_mp4_module

    #make && make install
  2. nginx 설정 파일에 해당 스크립트 추가
    location /video/ {
    mp4;
    mp4_buffer_size 1m;
    mp4_max_buffer_size 5m;
    mp4_limit_rate on;
    mp4_limit_rate_after 30s;
    }
  3. nginx 재시작
  4. 웹사이트로 들어가서 스트리밍 확인