nginx編譯安裝與常規配置

  Nginx 是一個高性能的 HTTP 和 反向代理服務器,也是一個 IMAP/POP3/SMTP 代理服務器。Nginx 編譯安裝比較簡單,難點在於配置

優點:

    支持高達 50,000 個併發連接數的響應,Nginx爲我們選擇了 epoll and kqueue作爲開發模型。

  Nginx作爲負載均衡服務器:Nginx 既可以在內部直接支持 Rails 和 PHP 程序對外進行服務,也可  以支持作爲 HTTP代理服務器對外進行服務。Nginx採用C進行編寫,不論是系統資源開銷還是CPU使用效率都比 Perlbal 要好很多。

  作爲郵件代理服務器:Nginx 同時也是一個非常優秀的郵件代理服務器

  Nginx 是一個安裝非常的簡單,配置文件非常簡潔(還能夠支持perl語法),Bugs非常少的服務器:Nginx 啓動特別容易,並且幾乎可以做到7*24不間斷運行,即使運行數個月也不需要重新啓動。你還能夠不間斷服務的情況下進行軟件版本的升級。

step 1 模塊依賴性

yum -y install gcc openssl-devel pcre-devel zlib-devel

step 2 編譯安裝

groupadd nginx
useradd -g nginx -s /bin/false -M nginx
tar -zxf nginx-1.8.0.tar.gz
cd nginx-1.8.0
./configure \  
--prefix=/usr \
--sbin-path=/usr/sbin/nginx \
--conf-path=/etc/nginx/nginx.conf \
--error-log-path=/var/log/nginx/error.log \
--http-log-path=/var/log/nginx/access.log \
--pid-path=/var/run/nginx/nginx.pid  \
--lock-path=/var/lock/nginx.lock \
--user=nginx \
--group=nginx \
--with-http_ssl_module \
--with-http_flv_module \
--with-http_stub_status_module \
--with-http_gzip_static_module \
--http-client-body-temp-path=/var/tmp/nginx/client/ \
--http-proxy-temp-path=/var/tmp/nginx/proxy/ \
--http-fastcgi-temp-path=/var/tmp/nginx/fcgi/ 

make && make install
makdir -p /var/log/nginx

step 3 常規配置

user  nginx;
worker_processes  12;
worker_cpu_affinity 000000000001 000000000010 000000000100 000000001000 000000010000 000000100000 000001000000 000010000000 000100000000 001000000000 010000000000 100000000000;

worker_rlimit_nofile 102400;

error_log  /var/log/nginx/error.log warn;
pid        /var/run/nginx.pid;


events {
    worker_connections  102400;
    multi_accept        on;
    use                 epoll;
}


http {
    include       /etc/nginx/mime.types;
    default_type  application/octet-stream;
    server_names_hash_bucket_size 128;
    client_header_buffer_size 16k;
    large_client_header_buffers 4 16k;
    client_max_body_size 50m;
    sendfile on;

    access_log  off;
    
    tcp_nopush     on;
    tcp_nodelay        on;
    server_tokens off;
   

    keepalive_timeout 60 60;
    fastcgi_connect_timeout 300;
    fastcgi_send_timeout 300;
    fastcgi_read_timeout 300;
    fastcgi_buffer_size 64k;
    fastcgi_buffers 8 64k;
    fastcgi_busy_buffers_size 128k;
    fastcgi_temp_file_write_size 128k;
    fastcgi_intercept_errors on;

    gzip             on;
    gzip_min_length  1000;
    gzip_proxied     expired no-cache no-store private auth;
    gzip_types       text/plain text/css text/xml text/javascript application/x-javascript application/xml application/rss+xml application/xhtml+xml application/atom_xml;
    gzip_disable "MSIE [1-6].(?!.*SV1)";
    log_format  access  '$remote_addr - $remote_user [$time_local] "$request" $status $body_bytes_sent "$http_referer"  "$http_user_agent" $http_x_forwarded_for';

    include /etc/nginx/conf.d/*.conf;
}
upstream   www.cloudray.cn {
                   server   192.168.10.144:80 weight=10  max_fails=2 fail_timeout=5s;
                   server   192.168.10.188:80 weight=10  max_fails=2 fail_timeout=5s;

                   keepalive 60;
    }

server {
        listen       80;
        server_name  www.cloudray.cn;

        #charset koi8-r;

        #access_log  /var/log/nginx/www.cloudray.cn.log   main;

        location / {
                 proxy_pass         http://www.cloudray.cn;
                 proxy_http_version 1.1;
                 proxy_redirect     off;
                 proxy_set_header Connection "";

         }
server
{
    listen 80; #listen end
    server_name lelady.cn www.cloudray.cn; #server_name end
    index index.html index.htm index.php; #index end

    set $subdomain '';
    root  /home/wwwroot/lnmp/domain/www.cloudray.cn/web$subdomain;

    #error_page
    location ~ /ErrorPages/(400|401|403|404|405|502|503)\.html$ 
    {
        root /home/wwwroot/lnmp/domain/www.cloudray.cn/web;
    }


    location ~ .*\.php$
    {
                 fastcgi_pass unix:/var/run/php-fpm.sock;
                 fastcgi_index  index.php;
                 fastcgi_param  SCRIPT_FILENAME $document_root$fastcgi_script_name;
                 include        fastcgi_params;
                 fastcgi_param DOCUMENT_ROOT  /home/wwwroot/lnmp/domain/www.cloudray.cn/web$subdomain;
         fastcgi_param SCRIPT_FILENAME  /home/wwwroot/lnmp/domain/www.cloudray.cn/web$subdomain$fastcgi_script_name;
    }

    location ~ .*\.(gif|jpg|jpeg|png|bmp|swf|flv|mp3|wma)$
    {
                 expires      30d;
                 valid_referers none blocked www.cloudray.cn cloudray.cn;
                 if ($invalid_referer) {
                         return 502;
                  }
    }

    location ~ .*\.(js|css)$
    {
         expires      12h;
    }

    #access_log /home/wwwroot/lnmp/logs/www.cloudray.cn-access.log combined; #access_log end
    access_log off;
    error_log /home/wwwroot/lnmp/logs/www.cloudray.cn-error.log crit; #error_log end
}


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章