«   2024/05   »
1 2 3 4
5 6 7 8 9 10 11
12 13 14 15 16 17 18
19 20 21 22 23 24 25
26 27 28 29 30 31
Archives
Today
Total
관리 메뉴

VIDEOCUBE

Nginx 설치하기 본문

시스템

Nginx 설치하기

라떼청년 2017. 11. 25. 01:47
# yum으로 nginx를 설치하기위해 먼저 아래의 파일을 설치합니다.


root@linux-01:/root> rpm -ivh http://nginx.org/packages/centos/6/noarch/RPMS/nginx-release-centos-6-0.el6.ngx.noarch.rpm


http://nginx.org/packages/centos/6/noarch/RPMS/nginx-release-centos-6-0.el6.ngx.noarch.rpm(을)를 복구합니다

경고: /var/tmp/rpm-tmp.XAz0lA: Header V4 RSA/SHA1 Signature, key ID 7bd9bf62: NOKEY

준비 중...               ########################################### [100%]

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


root@linux-01:/etc/yum.repos.d> cat nginx.repo 

# nginx.repo


[nginx]

name=nginx repo

baseurl=http://nginx.org/packages/centos/6/$basearch/

gpgcheck=0

enabled=1



root@linux-01:/etc/yum.repos.d> yum --disablerepo=* --enablerepo=nginx install nginx



root@linux-01:/etc/nginx> tree

.

├── conf.d

│   └── default.conf

├── fastcgi_params

├── koi-utf

├── koi-win

├── mime.types

├── modules -> ../../usr/lib64/nginx/modules

├── nginx.conf

├── scgi_params

├── uwsgi_params

└── win-utf


2 directories, 9 files



서비스 상태


nginx          0:해제 1:해제 2:활성 3:활성 4:활성 5:활성 6:해제

nginx-debug    0:해제 1:해제 2:해제 3:해제 4:해제 5:해제 6:해제



서비스 시작


root@linux-01:/etc/nginx/conf.d> service nginx start

nginx (을)를 시작 중:                                      [  OK  ]



네트워크 상태


root@linux-01:/etc/nginx/conf.d> netstat -nlp

Active Internet connections (only servers)

Proto Recv-Q Send-Q Local Address               Foreign Address             State       PID/Program name   

tcp        0      0 0.0.0.0:80                  0.0.0.0:*                   LISTEN      1132/nginx          

tcp        0      0 0.0.0.0:22                  0.0.0.0:*                   LISTEN      911/sshd            

tcp        0      0 127.0.0.1:25                0.0.0.0:*                   LISTEN      988/master          

tcp        0      0 :::22                       :::*                        LISTEN      911/sshd            

tcp        0      0 ::1:25                      :::*                        LISTEN      988/master


실행 프로세스

1 S root      1132 1  0  80 0 - 11382 rt_sig 01:02 ?00:00:00 nginx: master process /usr/sbin/nginx -c /etc/nginx/nginx.conf

5 S nginx    1135 1132  0  80   0 - 11479 ep_pol 01:02 ?00:00:00 nginx: worker process



실행권한

[user]

nginx:!!:17494::::::

[group]

nginx:x:499:


nginx:x:498:499:nginx user:/var/cache/nginx:/sbin/nologin




vi /etc/security/limits.conf 설정

ㄴ 다음 두 행 추가



* soft nofile 65536 * hard nofile 65536


설정 전 [ 기본 ]

root@linux-01:/root> ulimit -n

1024



설정 후

root@linux-01:/root> ulimit -n

65536

root@linux-01:/root> let b=65536/4

root@linux-01:/root> echo $b

16384

설정파일

/etc/nginx/nginx.conf


user  nginx;                                 //사용자는 nginx

worker_processes  1;                         //몇개의 thread 가 사용될지 정의한다. cpu cores 수를 지정한다다


error_log  /var/log/nginx/error.log warn;    //경고, 에러 /var/log/nginx/error.log 경로 설정

pid        /var/run/nginx.pid;               //PID 파일 경로



events {

    worker_connections  1024;      //16384 까지 가능함          

//worker_processes * worker_connections / 4 이 값은 ulimit -n 의 결과값(open files)보다 작아야 한다

// 1 * 65536 / 4

}


//HTTP 설정

http {

    include       /etc/nginx/mime.types;          //mime type 설정

    default_type  application/octet-stream;        //default


    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  /var/log/nginx/access.log  main;    //access.log 위치


    sendfile        on;                            

    #tcp_nopush     on;


    keepalive_timeout  65;


    #gzip  on;


    include /etc/nginx/conf.d/*.conf;    // /etc/nginx/conf.d/안에 conf 확장자를 가진 모든 파일을 추가한다다

}


/etc/nginx/conf.d/default.conf


server {

    listen       80;                            //port 설정

    server_name  localhost;                     //


    #charset koi8-r;

    #access_log  /var/log/nginx/host.access.log  main;


    location / {

        root   /usr/share/nginx/html;            //Document 세팅

        index  index.html index.htm;             //index page 세팅

    }


    #error_page  404              /404.html;        //404 에러 발생시 page location


    # redirect server error pages to the static page /50x.html

    #

    error_page   500 502 503 504  /50x.html;

    location = /50x.html {

        root   /usr/share/nginx/html;                //50x 에러 발생시 page location

    }


    # proxy the PHP scripts to Apache listening on 127.0.0.1:80

    #

    #location ~ \.php$ {

    #    proxy_pass   http://127.0.0.1;                //proxy 구성    php

    #}


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

    #}

}



방화벽 설정


lokkit -s http


root@linux-01:/etc/nginx/conf.d> iptables -L

Chain INPUT (policy ACCEPT)

target     prot opt source               destination         

ACCEPT     all  --  anywhere             anywhere            state RELATED,ESTABLISHED 

ACCEPT     icmp --  anywhere             anywhere            

ACCEPT     all  --  anywhere             anywhere            

ACCEPT     tcp  --  anywhere             anywhere            state NEW tcp dpt:ssh 

ACCEPT     tcp  --  anywhere             anywhere            state NEW tcp dpt:http 

REJECT     all  --  anywhere             anywhere            reject-with icmp-host-prohibited 


Chain FORWARD (policy ACCEPT)

target     prot opt source               destination         

REJECT     all  --  anywhere             anywhere            reject-with icmp-host-prohibited 


Chain OUTPUT (policy ACCEPT)

target     prot opt source               destination   







웹브라우저



Performance 관련된 내용은 다음을 참고


http://kwonnam.pe.kr/wiki/nginx/performance

반응형
Comments