본문 바로가기
카테고리 없음

Nginx - Guide

by boolean 2017. 7. 29.
728x90
  • LINK: Install Nginx to the latest version on Ubuntu servers
  • LINK: Upgrading Nginx to the latest version on Ubuntu servers
  • LINK: Install Openssl on Ubuntu servers
  • Install Nginx to the latest version on Ubuntu servers

    추천 패키지 설치 : 오래된 버전인 경우가 많음

    $sudo aptitude search nginx

    $sudo apt-get install nginx-full // nginx-light and so on......

    $nginx -v

    nginx의 공식 홈페이지를 통해서 추천되는 비공식 패키지 설치 :안정적(stable) 최신버전(development)

    $sudo aptitude install software-properties-common

    $sudo add-apt-repository ppa:nginx/development

    $sudo apt-get update

    $sudo apt-get install nginx

    $nginx -v


    Upgrading Nginx to the latest version on Ubuntu servers

    $nginx -v

    nginx version: nginx/1.1.19

    $sudo cp /etc/nginx/nginx.conf /etc/nginx/nginx.conf.1.1.19.backup       //backup

    $sudo service nginx stop

    $sudo aptitude install python-software-properties                             //Install the dependencies

    $sudo add-apt-repository ppa:nginx/stable  

    $sudo aptitude update

    $sudo aptitude safe-upgrade

    $sudo service nginx restart

    $nginx -v

    nginx version: nginx/1.4.7


    Install Openssl on Ubuntu servers

    $sudo su

    enter user password :

    #cd /usr/local/ssl

    # wget http://www.openssl.org/source/openssl-1.0.1i.tar.gz

    # tar -xvf openssl-1.0.1i.tar.gz

    # cd openssl-1.0.1i

    # ./config

    # make

    # make test

    # make install

    #vi /etc/bash.bashrc

    export PATH=/usr/local/ssl/bin:$PATH

    export LD_LIBRARY_PATH=/usr/local/ssl/lib:$LD_LIBRART_PATH

    # source /etc/bash.bashrc

    #cp /usr/local/ssl/bin/openssl /usr/bin

    # openssl version


    $openssl genrsa -out example.com.key 2048 //Create private.key $openssl req -new -sha256 -key example.com.key -out example.com.csr //Certificate Signing Request Country Name (2 letter code) [AU]:KR(국가코드) State or Province Name (full name) [Some-State]:Korea(국가) Locality Name (eg, city) []:Seout(지역) Organization Name (eg, company) [Internet Widgits Pty Ltd]:<회사명> Organizational Unit Name (eg, section) []:<부서명> Common Name (e.g. server FQDN or YOUR name) []: Email Address []:<이메일> Please enter the following 'extra' attributes to be sent with your certificate request A challenge password []:<비밀번호> An optional company name []:<비밀번호>

    자체 서명된 SSL 인증서를 생성

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

    Signature ok
    subject=/C=KR/ST=Seout/L=Seout/O=xxxx/OU=Dev./CN=www.neel.pe.kr/emailAddress=nell@pe.kr

    Getting Private key



    웹서버 인증서 파일 (.crt) 파일이 만들어짐


    # ll
    -rw-r--r--.  1 root root     1265 Jan  7 15:02 nell.crt
    -rw-r--r--.  1 root root     1070 Jan  7 14:55 nell.csr
    -rw-r--r--.  1 root root     1708 Jan  7 14:55 nell.key




    서버가 구동될때마다 개인 키에 설정된 PassPhrase를 물어보게 되므로 자동으로 모두 처리되도록 하기 위해 PassPhrase 제거


    # cp nell.key nell.key.secure

    openssl rsa -in <파일명>.key.secure -out <파일명>.key
    writing RSA key





    -------------------------------------------------------




    Nginx에 SSL 적용!



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

    # HTTPS 부분에 아랫부분을 변경하여 준다.



        # HTTPS server

            server {
             listen       443;
             server_name  localhost;


             ssl     on;
             ssl_certificate /usr/local/nginx/ssl/nell.crt;                  //   crt 경로)
             ssl_certificate_key     /usr/local/nginx/ssl/nell.key;       //   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   html;       // 홈페이지 경로
                index  index.html index.htm;
            }
        }
    }







    nginx에 ssl 모듈 확인






    #/usr/local/nginx/sbin/nginx -V

    nginx version: nginx/1.7.8
    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


    "--with-http_ssl_module" 이부분이 없다면 모듈을 설치해 줘여한다.




    모듈 컴파일


    #cd /usr/local/src/nginx-1.7.9

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

    # make && make install



    # /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


    "syntax is ok"가 뜬다면 정상이라는 뜻이다.




    #/etc/init.d/nginx restart


    웹에서 https:// xxxxxxx 확인


    댓글