Programming/Etc2016. 1. 22. 18:13

auth_basic 의 경우 평문으로 패스워드가 전송되면서 해킹 위험있음


그 방안으로 SSL도 있지만 간단한 내부 웹사이트의 경우 http-auth-digest 로 활용하는 방안도 괜찮은 방법이다.


https://www.nginx.com/resources/wiki/modules/auth_digest/


nginx 다운로드

http://nginx.org/en/download.html


nginx-http-auth-digest 다운로드 ( 아래에서 받을것 그래야지 1.8이상에서 문제없다 )

https://github.com/atomx/nginx-http-auth-digest


$ tar xvfz nginx-1.8.0.tar.gz
$ unzip nginx-http-auth-digest-master.zip
$ cd nginx-1.8.0
$ ./configure --prefix=/data/nginx --conf-path=/etc/nginx/nginx.conf --user=www-data --group=www-data --with-http_ssl_module --add-module=../nginx-http-auth-digest-master 
$ make
$ make install


비번파일만들기

nginx-http-auth-digest 디렉토리보면 htdigest.py 파일이 존재함

$ python htdigest.py /etc/nginx/digest/www.digest admin admin_web


Conf 설정

auth_digest_user_file /etc/nginx/digest/www.digest;
auth_digest_shm_size 4m;
location / {
    auth_digest 'admin_web';
    auth_digest_timeout 60s;
    auth_digest_expires 10s;
    auth_digest_replays 20;
    proxy_pass http://localhost:8080/;
    proxy_redirect off;
}


Posted by 시니^^
SERVER/Nginx2015. 12. 10. 04:31

http://nginx.org/en/docs/http/ngx_http_ssi_module.html


보통은 웹어플리케이션단에서 include 기능을 지원하기 때문에 별 의미가 없을 수 있지만


요즘 같이 api 서버 따로 만들고 웹UI 개발쪽에서 html / css 작업 개별로 할 경우에


굳이 ws에 추가 어플리케이션을 깔지 않고 nginx만으로도 아래와 같이 include가 구현이 가능하다.



 include

Includes the result of another request into a response. The command has the following parameters:
file
specifies an included file, for example:
<!--# include file="footer.html" -->



그 이외에도 다양한 Command 처리가 많으니까 참고하면 좋을 듯하다.


Posted by 시니^^
SERVER/Nginx2015. 12. 10. 04:25

http://nginx.org/en/docs/http/ngx_http_sub_module.html


Example Configuration

location / {
    sub_filter '<a href="http://127.0.0.1:8080/'  '<a href="https://$host/';
    sub_filter '<img src="http://127.0.0.1:8080/' '<img src="https://$host/';
    sub_filter_once on;
}


위와 같이 특정 url 주소를 라이브 환경과 개발환경등 서버 셋팅환경에 따라서 다르게 적용해야되는 경우 활용하기 좋다


특히 개발존에서 CDN URL 로 개발하고 실제 해당 url들은 내부개발망 자체 img 나 js url를 보도록 한다던지 하면 소스 업로드할 때 소스 수정부분을 덜 수 있는 방안중에 하나 이기도 하다.

물론 어플리케이션단에서 빌드시 자동화 해놓았다면 크게 신경 쓸 내용은 아니지만...


그리고 해당 모듈을 이용하기 위해서는 설치시 --with-http_sub_module 지정을 해줘야만 한다.  

Posted by 시니^^
SERVER/Nginx2015. 12. 10. 04:19

http://nginx.org/en/docs/http/ngx_http_geo_module.html


nginx conf에서 아래 형태와 같이 각각의 아이피 별로 변수값을 지정 할 수 있다.

Example Configuration

geo $geo {
    default        0;

    127.0.0.1      2;
    192.168.1.0/24 1;
    10.1.0.0/16    1;

    ::1            2;
    2001:0db8::/32 1;
}


그래서 해당 변수를 이용해서 아래와 같이 특정 아이피 경우 Rewrite 시킨다던지 location 처리를 다르게 등 여러 방안으로 이용 할 수 있다. 점검시에 내부 아이피만 처리하고 외부 아이피는 notice페이지로 리다이렉트 시키다던지등 상황에 따라서 잘 활용하면 좋을 듯하다.


if ( $request_uri ~ /test_page ){ set $geo 1; } if ( $geo = 0 ){ rewrite ^ /test_page?; } if ($geo = 2) { proxy_pass http://ttt; break; }



Posted by 시니^^
SERVER/Nginx2014. 8. 29. 15:28
IE나 크롬 개발자 도구로 Response Headers 보게 되면  아래와 같이 서버버젼과 PHP버젼이 적나하게 보이는 경우가 있다
항상 버젼 업데이트를 한다고 하면 문제 없겠지만 늘 버그/보안취약점이 나와서 버젼 업데이트가 되고 있는 중에 
해당 버젼을 확인하고 취약점을 해킹하는 경우가 발생한다 그래서 해당 정보의 경우 숨기는 게 보다 안전하다고 생각된다.

  1. Cache-Control:
    no-store, no-cache, must-revalidate, post-check=0, pre-check=0
  2. Connection:
    keep-alive
  3. Content-Type:
    text/html; charset=UTF-8
  4. Date:
    Fri, 29 Aug 2014 06:22:59 GMT
  5. Expires:
    Thu, 19 Nov 1981 08:52:00 GMT
  6. Pragma:
    no-cache
  7. Server:
    nginx/1.6.1
  8. Transfer-Encoding:
    chunked
  9. X-Powered-By:
    PHP/5.5.15


※ X-Powered-By:PHP/5.5.15 삭제

vi /etc/php.ini

expose_php = Off <== OFF로 변경


※ Nginx 숨기기

http://wiki.nginx.org/HttpCoreModule#server_tokens

vi /etc/nginx/nginx.conf

server_tokens off; <==내용추가함


=> php와 nginx수정하였다면 php-fpm과 nginx 재시작해줘야됨


※ Nginx라는 서버이름을 바꾸고 싶을때

1. HttpHeadersMoreModule 추가모듈설치 하여서 셋팅

http://wiki.nginx.org/HttpHeadersMoreModule#Installation

※ 소스설치시 추가하면됨

./configure --prefix=/opt/nginx --add-module=/path/to/headers-more-nginx-module

※ set the Server output header 

    more_set_headers 'Server: my-server';


2. 컴파일전에 소스코드에서 해당내용 삭제 또는 변경 

http://forum.nginx.org/read.php?11,1646

vi /path/to/nginx-0.*/src/http/ngx_http_header_filter_module.c lines 48 and 49:

====================================================

static char ngx_http_server_string[] = "Server: nginx" CRLF;

static char ngx_http_server_full_string[] = "Server: " NGINX_VER CRLF;

====================================================


※ Apache 경우

vi /etc/httpd/conf/httpd.conf

ServerTokens Prod

ServerSignature Off

=====================================================

ServerTokens Prod[uctOnly] => Server: Apache
ServerTokens Major => Server: Apache/2
ServerTokens Minor => Server: Apache/2.0
ServerTokens Min[imal] => Server: Apache/2.0.41
ServerTokens OS : Server => Apache/2.0.41 (Unix)
ServerTokens Full : Server => Apache/2.0.41 (Unix) PHP/4.2.2 MyMod/1.2


Posted by 시니^^
SERVER/Nginx2014. 5. 21. 15:01

http://wiki.nginx.org/Install


Nginx yum install( CentOS6 )


1) nginx 에서 제공해주는 저장소 등록

$ rpm -Uvh http://nginx.org/packages/centos/6/noarch/RPMS/nginx-release-centos-6-0.el6.ngx.noarch.rpm

Retrieving http://nginx.org/packages/centos/6/noarch/RPMS/nginx-release-centos-6-0.el6.ngx.noarch.rpm

warning: /var/tmp/rpm-tmp.U4wAT5: Header V4 RSA/SHA1 Signature, key ID 7bd9bf62: NOKEY

Preparing...                ########################################### [100%]

   1:nginx-release-centos   ########################################### [100%]

$ ll /etc/yum.repos.d/

-rw-r--r--  1 root root  113 Oct 14  2011 nginx.repo

$ yum repolist

nginx                                                              nginx repo                                                                        56

===================================================================================================

CentOS 5.x :

wget http://nginx.org/packages/centos/5/noarch/RPMS/nginx-release-centos-5-0.el5.ngx.noarch.rpm

rpm -Uvh nginx-release-centos-5-0.el5.ngx.noarch.rpm

CentOS 6.x :

wget http://nginx.org/packages/centos/6/noarch/RPMS/nginx-release-centos-6-0.el6.ngx.noarch.rpm

rpm -Uvh nginx-release-centos-6-0.el6.ngx.noarch.rpm

===================================================================================================


2) yum install

$ yum install nginx

=================================================================================================================

 Package                           Arch                             Version                                     Repository                         Size

=================================================================================================================

Installing:

 nginx                             x86_64                           1.6.0-1.el6.ngx                             nginx                             335 k


3) conf 설정파일

$ vi /etc/nginx/nginx.conf

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


4) Nginx 실행 및 명령어

$ /etc/init.d/nginx 

Usage: nginx {start|stop|restart|condrestart|try-restart|force-reload|upgrade|reload|status|help|configtest}

$ /etc/init.d/nginx start

Starting nginx: [  OK  ]

$ ps aux | grep nginx

root     30106  0.0  0.0  45040  1124 ?        Ss   14:52   0:00 nginx: master process /usr/sbin/nginx -c /etc/nginx/nginx.conf

nginx    30107  0.0  0.0  45412  1732 ?        S    14:52   0:00 nginx: worker process  


 

 

 

※ 소스설치

소스파일 다운로드 : http://nginx.org/en/download.html 

컴파일 옵션 참조 : http://wiki.nginx.org/InstallOptions





Posted by 시니^^
SERVER/Nginx2014. 2. 24. 16:32

location ~* .(jpg|jpeg|png|gif|ico|css|js)$ {

    expires 365d;

}


location ~* \.(?:ico|css|js|gif|jpeg|png)$ {

    expires max;

    add_header Pragma public;

    add_header Cache-Control "public, must-reval!idate, proxy-reval!idate";

}


location ~* .(jpg|jpeg|png|gif|ico|css|js)$ {

    expires 365d;

}


location ~* \favicon.ico${

    access_log off;

    expires 1d;

    add_header Cache-Control public;

}


location ~*^.+.(jpg|swf|jpeg|gif|css|png|js|ico)$ {

    access_log off;

    expires 30d;

    add_header Cache-Control public;

}


// Nginx Cache Disable 엔진엑스 서버단에서 캐쉬끄기

http://serverfault.com/questions/269420/disable-caching-when-serving-static-files-with-nginx-for-development

server {

  server_name  static.server.local;

  root /var/www/static;


  ## Default location

  location / {

    access_log        off;

    expires           0;

    add_header        Cache-Control private;

  } 

}

Posted by 시니^^