Nginx源碼安裝

CentOS7下安裝nginx+sticky

1.安裝編譯環境

安裝make:

yum -y install gcc automake autoconf libtool make

安裝g++:

yum install gcc-c++

2.安裝Nginx依賴包

安裝OpenSSL

wget ftp://ftp.openssl.org/source/openssl-1.0.2j.tar.gz

tar zxvf openssl-1.0.2j.tar.gz
cd openssl-1.0.2j/
./config --prefix=/usr/local --openssldir=/usr/local/ssl
make && make install

./config shared --prefix=/usr/local --openssldir=/usr/local/ssl
make clean
make && make install

安裝zlib庫

wget http://zlib.net/zlib-1.2.8.tar.gz

tar zxvf zlib-1.2.8.tar.gz
cd zlib-1.2.8/
./configure --prefix=/usr/local
make && make install 

安裝pcre庫

wget ftp://ftp.csx.cam.ac.uk/pub/software/programming/pcre/pcre-8.39.tar.gz

tar zxvf pcre-8.39.tar.gz
cd pcre-8.39/
./configure --prefix=/usr/local
make && make install 

3.安裝Nginx

wget http://nginx.org/download/nginx-1.10.2.tar.gz
tar zxvf nginx-1.10.0.tar.gz
wget https://bitbucket.org/nginx-goodies/nginx-sticky-module-ng/get/master.tar.gz
tar zvxf master.tar.gz
mv nginx-goodies-nginx-sticky-module-ng-08a395c66e42/ nginx-sticky-module
cd nginx-1.10.0/

./configure --sbin-path=/usr/local/nginx/nginx \
--conf-path=/usr/local/nginx/conf/nginx.conf \
--pid-path=/usr/local/nginx/nginx.pid \
--with-http_ssl_module \
--with-pcre=/root/pcre-8.39 \
--with-zlib=/root/zlib-1.2.8 \
--with-openssl=/root/openssl-1.0.2j \
--add-module=/root/nginx-sticky-module

make
make install

–with-pcre=/root/pcre-8.39 指的是 pcre-8.39 的源碼路徑
–with-zlib=/root/zlib-1.2.8 指的是 zlib-1.2.8 的源碼路徑
–with-openssl=/root/openssl-1.0.2j 指的是 openssl-1.0.2j 的源碼路徑

4.配置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;
    upstream idap {
        sticky;
        server 10.47.0.96:7080;
        server 10.47.0.96:7070;
    }

    server {
        listen       80;
        server_name  localhost;

        #charset koi8-r;

        #access_log  logs/host.access.log  main;

        location / {
            proxy_pass                          http://idap;
            proxy_set_header Host               $host;
            proxy_set_header X-Real-IP          $remote_addr;
            proxy_set_header X-Forwarded-For    $proxy_add_x_forwarded_for;
        }

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

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