레이블이 nginx인 게시물을 표시합니다. 모든 게시물 표시
레이블이 nginx인 게시물을 표시합니다. 모든 게시물 표시

2016년 2월 26일 금요일

Nginx Webalizer for geoip setting


When i use nginx & webalizer

Country data graph "country unresolved/Unkown" 100%.

this problem can fix using change settings.

1. Check Nginx module

$nginx  -V
nginx version: nginx/1.4.6 (Ubuntu)
built by gcc 4.8.4 (Ubuntu 4.8.4-2ubuntu1~14.04)
TLS SNI support enabled
configure arguments: --with-cc-opt='-g -O2 -fstack-protector --param=ssp-buffer-size=4 -Wformat -Werror=format-security -D_FORTIFY_SOURCE=2' --with-ld-opt='-Wl,-Bsymbolic-functions -Wl,-z,relro' --prefix=/usr/share/nginx --conf-path=/etc/nginx/nginx.conf --http-log-path=/var/log/nginx/access.log --error-log-path=/var/log/nginx/error.log --lock-path=/var/lock/nginx.lock --pid-path=/run/nginx.pid --http-client-body-temp-path=/var/lib/nginx/body --http-fastcgi-temp-path=/var/lib/nginx/fastcgi --http-proxy-temp-path=/var/lib/nginx/proxy --http-scgi-temp-path=/var/lib/nginx/scgi --http-uwsgi-temp-path=/var/lib/nginx/uwsgi --with-debug --with-pcre-jit --with-ipv6 --with-http_ssl_module --with-http_stub_status_module --with-http_realip_module --with-http_addition_module --with-http_dav_module --with-http_geoip_module --with-http_gzip_static_module --with-http_image_filter_module --with-http_spdy_module --with-http_sub_module --with-http_xslt_module --with-mail --with-mail_ssl_module

Nginx must include http_geoip_module module.

2. Download GeoIP databases

$mkdir /etc/nginx/geoip && cd /etc/nginx/geoip
$wget http://geolite.maxmind.com/download/geoip/database/GeoLiteCountry/GeoIP.dat.gz
$wget http://geolite.maxmind.com/download/geoip/database/GeoLiteCity.dat.gz
$gunzip GeoIP.dat.gz
$gunzip GeoLiteCity.dat.gz

3. Configure Nginx 

-add configure code
$nano /etc/nginx/nginx.conf

...
http {
        ....
        ##
        # geoip settings
        ##
        geoip_country   /etc/nginx/geoip/GeoIP.dat;             # the country IP database
        geoip_city      /etc/nginx/geoip/GeoLiteCity.dat;       # the city IP database
        ...
}

-add configure code
$nano /etc/nginx/fastcgi_params

...
### SET GEOIP Variables ###
fastcgi_param GEOIP_COUNTRY_CODE $geoip_country_code;
fastcgi_param GEOIP_COUNTRY_CODE3 $geoip_country_code3;
fastcgi_param GEOIP_COUNTRY_NAME $geoip_country_name;

fastcgi_param GEOIP_CITY_COUNTRY_CODE $geoip_city_country_code;
fastcgi_param GEOIP_CITY_COUNTRY_CODE3 $geoip_city_country_code3;
fastcgi_param GEOIP_CITY_COUNTRY_NAME $geoip_city_country_name;
fastcgi_param GEOIP_REGION $geoip_region;
fastcgi_param GEOIP_CITY $geoip_city;
fastcgi_param GEOIP_POSTAL_CODE $geoip_postal_code;
fastcgi_param GEOIP_CITY_CONTINENT_CODE $geoip_city_continent_code;
fastcgi_param GEOIP_LATITUDE $geoip_latitude;
fastcgi_param GEOIP_LONGITUDE $geoip_longitude;

-add configure code
$nano /etc/nginx/proxy_params

....
### SET GEOIP Variables ###
proxy_set_header GEOIP_COUNTRY_CODE $geoip_country_code;
proxy_set_header GEOIP_COUNTRY_CODE3 $geoip_country_code3;
proxy_set_header GEOIP_COUNTRY_NAME $geoip_country_name;

proxy_set_header GEOIP_CITY_COUNTRY_CODE $geoip_city_country_code;
proxy_set_header GEOIP_CITY_COUNTRY_CODE3 $geoip_city_country_code3;
proxy_set_header GEOIP_CITY_COUNTRY_NAME $geoip_city_country_name;
proxy_set_header GEOIP_REGION $geoip_region;
proxy_set_header GEOIP_CITY $geoip_city;
proxy_set_header GEOIP_POSTAL_CODE $geoip_postal_code;
proxy_set_header GEOIP_CITY_CONTINENT_CODE $geoip_city_continent_code;
proxy_set_header GEOIP_LATITUDE $geoip_latitude;
proxy_set_header GEOIP_LONGITUDE $geoip_longitude;

4. Nginx reload!

$service nginx reload

5. + Webalizer configure

...
GeoIP           yes

# GeoIPDatabase specifies an alternate database filename to use by the
# GeoIP library.  If an absolute path is not given as part of the name
# (ie: starts with a leading '/'), then the name is relative to the
# default output directory. This option should not normally be needed.

GeoIPDatabase   /etc/nginx/geoip/GeoIP.dat
...

6. test result



Good Luck!





2016년 2월 5일 금요일

Nginx 폴더 지정해서 디렉토리 리스팅하기


Nginx 를 이번에 사용하게 되었는데요.

Nginx를 이용해서 폴더에 있는 파일을 받을 수 있게 하려합니다.

mac OS에서 테스트할때의 nginx 의 nginx.conf 파일은
/usr/local/etc/nginx/nginx.conf 경로에 있었습니다.

리눅스 우분투(Ubuntu)의 경우는
/etc/nginx/nginx.conf 경로에 있었습니다.

nginx.conf 파일을 보겠습니다.

#user  nobody;
worker_processes  1;

#error_log  logs/error.log;
#error_log  logs/error.log  notice;
#error_log  logs/error.log  info;

#pid        logs/nginx.pid;


events {
    worker_connections  1024;
}


http {
    include       mime.types;
    default_type  application/octet-stream;

    #log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
    #                  '$status $body_bytes_sent "$http_referer" '
    #                  '"$http_user_agent" "$http_x_forwarded_for"';

    #access_log  logs/access.log  main;

    sendfile        on;
    #tcp_nopush     on;

    #keepalive_timeout  0;
    keepalive_timeout  65;

    #gzip  on;

    server {
        listen       8080;
        server_name  localhost;

        #charset koi8-r;

        #access_log  logs/host.access.log  main;

        location / {
            root   html;
            index  index.html index.htm;
        }

        #error_page  404              /404.html;

        # redirect server error pages to the static page /50x.html
        #
        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   html;
        }

        # proxy the PHP scripts to Apache listening on 127.0.0.1:80
        #
        #location ~ \.php$ {
        #    proxy_pass   http://127.0.0.1;
        #}

        # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
        #
        #location ~ \.php$ {
        #    root           html;
        #    fastcgi_pass   127.0.0.1:9000;
        #    fastcgi_index  index.php;
        #    fastcgi_param  SCRIPT_FILENAME  /scripts$fastcgi_script_name;
        #    include        fastcgi_params;
        #}

        # deny access to .htaccess files, if Apache's document root
        # concurs with nginx's one
        #
        #location ~ /\.ht {
        #    deny  all;
        #}
    }


    # another virtual host using mix of IP-, name-, and port-based configuration
    #
    #server {
    #    listen       8000;
    #    listen       somename:8080;
    #    server_name  somename  alias  another.alias;

    #    location / {
    #        root   html;
    #        index  index.html index.htm;
    #    }
    #}


    # HTTPS server
    #
    #server {
    #    listen       443 ssl;
    #    server_name  localhost;

    #    ssl_certificate      cert.pem;
    #    ssl_certificate_key  cert.key;

    #    ssl_session_cache    shared:SSL:1m;
    #    ssl_session_timeout  5m;

    #    ssl_ciphers  HIGH:!aNULL:!MD5;
    #    ssl_prefer_server_ciphers  on;

    #    location / {
    #        root   html;
    #        index  index.html index.htm;
    #    }
    #}
    include servers/*;
}

위와 같이 nginx.conf 파일이 있을텐데요.

이 파일에서 코드 조금만 추가해주면 됩니다. (원래 하려고 했던 파일 제공만 하면되니까요.)

http {
}
이 괄호 안에 추가해주시면 되는데요
저는 이렇게 코드를 추가했습니다.

#user  nobody;
worker_processes  1;

#error_log  logs/error.log;
#error_log  logs/error.log  notice;
#error_log  logs/error.log  info;

#pid        logs/nginx.pid;


events {
    worker_connections  1024;
}


http {
    include       mime.types;
    default_type  application/octet-stream;

    #log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
    #                  '$status $body_bytes_sent "$http_referer" '
    #                  '"$http_user_agent" "$http_x_forwarded_for"';

    #access_log  logs/access.log  main;

    sendfile        on;
    #tcp_nopush     on;

    #keepalive_timeout  0;
    keepalive_timeout  65;

    gzip  on;

    server {
        ...
    }
    server {
        listen      8000;
        server_name localhost;

        location /datas/ {
                root /Users/moon1000_mac_mini/Desktop/datas;
                autoindex on;
        }
    }
    ...
    include servers/*;
}


위에서 제가 추가한 부분만 보면
server {
        listen      8000;
        server_name localhost;
        location /datas/ {
                root /Users/moon1000_mac_mini/Desktop/datas;
                autoindex on;
        }
}

위의 코드는
/datas/ 의 위치를 공개하겠다.
autoindex on 은 인덱스 페이지를 보여주는 것입니다.
그 외에는 공유가 안됩니다.
저 위치로 가보면,

Index of /datas/


../
img/                                             04-Feb-2016 07:34                   -
d3.zip                                           04-Feb-2016 07:34             8958481
d4.zip                                           04-Feb-2016 07:34            10485198
d5.zip                                           04-Feb-2016 07:34            15769563
d6.zip                                           04-Feb-2016 07:34            10722878
d7.zip                                           04-Feb-2016 07:34             9166886

이렇게 나옵니다.

다른 어려운 부분이 있다면 질문주세요.
Good luck!


2016년 1월 28일 목요일

nginx CLI command

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

"nginx -s [signal]"

$nginx -s stop         // fast shutdown
$nginx -s quit          // graceful shutdown
$nginx -s reload      // reloading the configuration files
$nginx -s reopen     // reopen the log files

//kill nginx process
$ ps -ax | grep nginx
21074 ??         0:00.00 nginx: master process nginx
21075 ??         0:00.00 nginx: worker process

21123 ttys000    0:00.01 grep nginx

$kill -s QUIT 21074
(kill master process)

mac install nginx using brew


just run 'brew install nginx'
$brew install nginx


mac:~ mac$ brew install nginx
==> Installing dependencies for nginx: openssl
==> Installing nginx dependency: openssl
==> Downloading https://homebrew.bintray.com/bottles/openssl-1.0.2e_1.el_capitan
######################################################################## 100.0%
==> Pouring openssl-1.0.2e_1.el_capitan.bottle.tar.gz
==> Caveats
A CA file has been bootstrapped using certificates from the system
keychain. To add additional certificates, place .pem files in
  /usr/local/etc/openssl/certs

and run
  /usr/local/opt/openssl/bin/c_rehash

This formula is keg-only, which means it was not symlinked into /usr/local.

Apple has deprecated use of OpenSSL in favor of its own TLS and crypto libraries

Generally there are no consequences of this for you. If you build your
own software and it requires this formula, you'll need to add to your
build variables:

    LDFLAGS:  -L/usr/local/opt/openssl/lib
    CPPFLAGS: -I/usr/local/opt/openssl/include

==> Summary
🍺  /usr/local/Cellar/openssl/1.0.2e_1: 465 files, 11.9M
==> Installing nginx
==> Downloading https://homebrew.bintray.com/bottles/nginx-1.8.0.el_capitan.bott
######################################################################## 100.0%
==> Pouring nginx-1.8.0.el_capitan.bottle.1.tar.gz
==> Caveats
Docroot is: /usr/local/var/www

The default port has been set in /usr/local/etc/nginx/nginx.conf to 8080 so that
nginx can run without sudo.

nginx will load all files in /usr/local/etc/nginx/servers/.

To have launchd start nginx at login:
  ln -sfv /usr/local/opt/nginx/*.plist ~/Library/LaunchAgents
Then to load nginx now:
  launchctl load ~/Library/LaunchAgents/homebrew.mxcl.nginx.plist
Or, if you don't want/need launchctl, you can just run:
  nginx
==> Summary

🍺  /usr/local/Cellar/nginx/1.8.0: 7 files, 940.1K

And you can change config file on this path
/usr/local/etc/nginx/nginx.conf

Good luck!

JIRA Plugin - ScriptRunner 소개 #2

관련 글 소개 #1:  https://pineoc.blogspot.com/2019/03/scriptrunner-1.html ScriptRunner 소개 #2 지난 글에서는 Behaviours를 보았고 다음 내용인 콘솔, 리스너 등을 ...