centos安装配置nginx

1、安装gcc

yum install gcc

2、安装PCRE,zlib,OpenSSL(其中devel,是develop开发包的意思)

 yum install -y pcre pcre-devel  

 yum install -y zlib zlib-devel  

 yum install -y openssl openssl-devel

3、下载并安装nginx

mkdir nginx-src && cd nginx-src
wget http://nginx.org/download/nginx-1.7.3.tar.gz
tar xzf nginx-1.7.3.tar.gz
cd nginx-1.7.3
./configure
make
make install
whereis nginx

4、sbin/nginx 启动nginx

启动:nginx
停止:nginx -s stop

5、配置

#启动进程,通常设置成和cpu的数量相等
worker_processes  1;

#全局错误日志及PID文件
error_log  /var/log/nginx/error.log;
pid        /var/run/nginx.pid;

#工作模式及连接数上限
events {
    use   epoll;             #epoll是多路复用IO(I/O Multiplexing)中的一种方式,但是仅用于linux2.6以上内核,可以大大提高nginx的性能
    worker_connections  1024;
}

#设定http服务器,利用它的反向代理功能提供负载均衡支持
http {
    include       mime.types;  #设定mime类型,类型由mime.type文件定义
    default_type  application/octet-stream;
    sendfile        on;

    #设置链接超时时间
    keepalive_timeout  65;
    
   #开启gzip压缩
   #    gzip  on;
   #    gzip_disable "MSIE [1-6].(?!.*SV1)";

  #设定负载均衡的服务器列表
   upstream mysvr {
    #weigth参数表示权值,权值越高被分配到的几率越大
    #    #本机上的Squid开启3128端口
    server 192.168.8.151:80  weight=6;
    server 192.168.8.120:80  weight=6;
        }

    server {
    #侦听80端口
        listen       80;
       #定义使用www.xx.com访问
        server_name  localhost;
    
        location / {
            root   html;
            index  index.html index.htm;
        }
        error_page   500 502 503 504  /50x.html;
        
    location = /50x.html {
            root   html;
        }

  location ~ .php$ {
        root /root;
        fastcgi_pass 127.0.0.1:9000;
        fastcgi_index index.php;
        fastcgi_param SCRIPT_FILENAME /home/www/www$fastcgi_script_name;
        include fastcgi_params;
    }
    #设定查看Nginx状态的地址
    #    location /NginxStatus {
    #   stub_status            on;
    #   access_log              on;
    #   auth_basic              "NginxStatus";
    #   auth_basic_user_file  conf/htpasswd;
    #        }
    #  #禁止访问 .htxxx 文件
    #  location ~ /.ht {
    #   deny all;
    #    }

    }



}
View Code
原文地址:https://www.cnblogs.com/fubaizhaizhuren/p/nginx.html