Linux 下nginx 安装

Linux 下nginx安装
1、安装pcre
从pcre的官网下载tar.gz
tar -zxvf pcre-8.38.tar.gz
cd pcre-8.38
./configure  
make
make install

2、安装zlib
从zlib的官网下载tar.gz包
tar -xvf zlib-1.2.11.tar.gz  
cd zlib-1.2.11
./configure  
make 
make install 

3、安装nginx
tar -zxvf nginx-1.9.15.tar.gz
cd nginx-1.9.15
./configure
make 
make install

4.启动 nginx
进入 /usr/local/nginx/sbin
./nginx

5.启动报错解决办法
报错信息
error while loading shared libraries: libpcre.so.1: cannot open shared object file: No such file or directory
解决方法:
ln -s /usr/local/lib/libpcre.so.1/lib64

6.停止
进入 /usr/local/nginx/sbin
./nginx -s stop

 

nginx 配置负载均衡,通过测试配置文件是ok的。

nginx.conf 如下

#user  nobody;

#工作的子进程数量(通常等于CPU数量或者2倍于CPU) 

worker_processes  1;

 

error_log  logs/error.log;

#error_log  logs/error.log  notice;

#error_log  logs/error.log  info;

扫描二维码关注公众号,回复: 525731 查看本文章

 

#pid        logs/nginx.pid;

events {

    #允许最大连接数 

    worker_connections  1024;

}

http {

      include       mime.types;

      default_type  application/octet-stream;

 

      server_names_hash_bucket_size 256;

      client_header_buffer_size 256k;

      large_client_header_buffers 4 256k;

 

      keepalive_timeout  120;

 

      client_max_body_size  50m;

      client_body_buffer_size  256k;

     

      proxy_connect_timeout    600; 

      proxy_read_timeout       600; 

      proxy_send_timeout       600; 

      proxy_buffer_size        16k; 

      proxy_buffers            4 64k; 

      proxy_busy_buffers_size 128k; 

      proxy_temp_file_write_size 128k; 

     

     fastcgi_connect_timeout 300;

     fastcgi_send_timeout 300;

     fastcgi_read_timeout 300;

     

     sendfile on;

     tcp_nodelay on;

     upstream mktinfo_pool{

           server   120.77.86.13:9001;

           server   120.77.145.156:9001;

     }

 

    server {

        listen  8080;

              server_name 127.0.0.1;

 

              location / {

                   proxy_pass  http://mktinfo_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;

              }

              access_log ./logs/access.log;

    }

 

 

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

    #    }

    #}

 

}

 

猜你喜欢

转载自taiwei-peng.iteye.com/blog/2353296