Linux resource limit

현재 OS상의 제한이 걸려 있는 목록을 볼 수 있는 명령어
ulimit -a

core file size          (blocks, -c) 0
data seg size           (kbytes, -d) unlimited
scheduling priority             (-e) 0
file size               (blocks, -f) unlimited
pending signals                 (-i) 7799
max locked memory       (kbytes, -l) 16384
max memory size         (kbytes, -m) unlimited
open files                      (-n) 1024
pipe size            (512 bytes, -p) 8
POSIX message queues     (bytes, -q) 819200
real-time priority              (-r) 0
stack size              (kbytes, -s) 8192
cpu time               (seconds, -t) unlimited
max user processes              (-u) 7799
virtual memory          (kbytes, -v) unlimited
file locks                      (-x) unlimited

위의 리스트 중에서 File open의 제약(Socket connect)을 걸고 있는 것이 바로
open files

ulimit -n 50000 혹은
/etc/security/limits.conf 파일에
* soft nofile 16384
* hard nofile 16384
을 추가후 껏다 키면 적용된다. (sysctl -p로도 적용될수도..?)

python에선 resourece 패키지를 통해 해당 스크립트가 실행되는 동안 변경할 수 있다.

import resource

soft, hard = 500000, 500000
resource.setrlimit(resource.RLIMIT_NOFILE, (soft, hard))

[Apache|Nginx] Reverse proxy Real IP

Front Nginx — Back Apache


Nginx

Setting Reverse Proxy with X-Real-IP

$ vi /etc/nginx/conf.d/<SomeReverseProxy>.conf

server {
    listen 80;

    server_name subdomain.silnex.kr;

    proxy_set_header X-Real-IP  $remote_addr;
    proxy_set_header X-Forwarded-For $remote_addr;
    proxy_set_header Host $host;

    proxy_pass http://127.0.0.1:8080;
}

 

Apache

Module Load

$ a2enmod remoteip

Create (or Edit) remoteip.conf 

$ vi /etc/apache2/conf-available/remoteip.conf

RemoteIPHeader X-Forwarded-For
RemoteIPTrustedProxy 127.0.0.1

than execute $ a2enconf remoteip

Edit apache2.conf(or httpd.conf)

$ vi /etc/apache/apache2.conf

## 수정 전 ##
#LogFormat "%h %l %u %t \"%r\" %>s %O \"%{Referer}i\" \"%{User-Agent}i\"" combined
#LogFormat "%h %l %u %t \"%r\" %>s %O" common 
## 수정 후 ##
LogFormat "%{X-Forwarded-For}i %l %u %t \"%r\" %>s %O \"%{Referer}i\" \"%{User-Agent}i\"" combined
LogFormat "%{X-Forwarded-For}i %l %u %t \"%r\" %>s %O" common

Restart apache service

$ service apache2 restart