Nginx 설치 표준

2884 단어
1. Nginx 설치
yum -y install nginx

2. nginx 메 인 프로필 nginx. conf 편집
/etc/nginx/nginx.conf
user  nginx nginx;

worker_processes 8;
worker_rlimit_nofile 65535; 

error_log  /opt/log/nginx/error.log notice;
#error_log  /var/log/nginx/error.log  info;

pid        /var/run/nginx.pid;

events {
    use epoll;
    worker_connections  51200;
}

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

log_format  main  "$remote_addr $remote_user [$time_local] '$request_method $host$request_uri' "
                  "$request_time $status $body_bytes_sent '$http_referer'"
                  " '$http_user_agent' '$http_x_forwarded_for'";

#    access_log  /opt/log/nginx/access.log  main;
    access_log  /dev/null;

    keepalive_timeout  65;

    server_names_hash_bucket_size 128;
    client_header_buffer_size 128k;
    large_client_header_buffers 4 256k;
    client_header_timeout  1m;
    client_body_timeout    1m;
    send_timeout           1m;
    sendfile                on;
    tcp_nopush     on;
    tcp_nodelay    on;
    client_max_body_size 50m;
    client_body_buffer_size 50m;
    #charset gb2312;

    proxy_connect_timeout 300;
    proxy_send_timeout 300;
    proxy_read_timeout 300;
    proxy_buffer_size 128k;
    proxy_buffers 2 256k;
    proxy_busy_buffers_size 256k;
    proxy_temp_file_write_size 256k;
    #proxy_intercept_errors  on;
    proxy_temp_path  /dev/shm/proxy_temp;
    fastcgi_temp_path  /dev/shm/fastcgi_temp;
    client_body_temp_path  /dev/shm/client_body_temp;

    gzip on;
    gzip_min_length 1k;
    gzip_buffers     4 16k;
    gzip_comp_level 2;
    gzip_http_version 1.1;
    gzip_types text/plain application/x-javascript text/css application/xml;
    gzip_vary on;

    server {
        listen *:80 default;
        server_name _ "";
        return 444;
        access_log   off;
    }

    include /etc/nginx/conf.d/*.conf;

}

3. 새 호스트 설정 예: test. 58. com, 백 엔 드 tomcat 호스트 10.58.11 / 12, 포트 8080
/etc/nginx/conf.d/test.58.com.conf
server {
    listen       80;
    server_name  test.58.com;
    access_log /opt/log/nginx/test.58.com_access.log main;
    charset utf-8;
    location / {
            proxy_pass http://test_pool;
            proxy_set_header  Host  $host;
            proxy_set_header X-Real-IP $remote_addr;
            proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    }
}

새 upstream
/etc/nginx/conf.d/jst2.58.com_upstream.conf
upstream  test_pool {
     server  10.58.1.11:8080 max_fails=2 fail_timeout=2s;
     server  10.58.1.12:8080 max_fails=2 fail_timeout=2s;
}

4. Nginx 시작
service nginx start
chkconfig --add nginx
chkconfig nginx --level 345 on

좋은 웹페이지 즐겨찾기