nginx环境搭建

【备注】nginx的作用,请自行百度。

【前提条件】

安装zlib 库、pcre,c++ 库等。在线安装方法:

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

有时候部分机器会报告异常: ./configure: error: C compiler cc is not found

执行如下命令:

yum -y install gcc gcc-c++ autoconf automake make 

【安装nignx】

上传nginx-1.8.0.tar.gz至服务器文件夹,这里以/alidata/software 目录为例:

# tar xvf nginx-1.8.0.tar.gz
# cd nginx-1.8.0
# ./configure --prefix=/alidata/service/nginx-1.8.0
(注意上面的安装位置/alidata/service/nginx-1.8.0 ,可以根据自己的需要设置)

# make
# make install
如果没有什么异常的话,恭喜你,安装成功。

【修改ngnix.conf配置文件】

具体的修订方法,请自行百度一下方案。这里仅仅给出个简单的配置样例。

替换掉 /alidata/service/nginx-1.8.0/conf 下面的文件

user  nobody;
worker_processes  2;
error_log   /alidata/service/nginx-1.8.0/logs/error.log;
pid        /alidata/service/nginx-1.8.0/logs/nginx.pid;
worker_rlimit_nofile 65536;

events {
    use epoll;
    worker_connections  65536;
}

http {
		include       mime.types;
    	default_type  application/octet-stream;
    
    	client_max_body_size 10m;    
    	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 /alidata/service/nginx-1.8.0/logs/access.log main;
    
    	sendfile        on;
    	#tcp_nopush     on;

    	keepalive_timeout  65;

    	#gzip  on;

	upstream xinghansoft {
		ip_hash;
		server 192.168.1.101:8088;
	}
	server {
		listen 80;
		server_name 192.168.1.101;
		charset utf-8;
		location / {
			proxy_set_header Host $host;
			proxy_set_header X-Real-IP $remote_addr;
	  		proxy_next_upstream error timeout invalid_header http_500 http_502 http_503 http_504;
			proxy_connect_timeout       150s;
			proxy_read_timeout          150s;
			proxy_set_header X-Forwarded-Host $host;
			proxy_set_header X-Forwarded-Server $host;
			proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
			proxy_pass     http://xinghansoft;
		}
	}

}
【启动nginx】

# cd /alidata/service/nginx-1.8.0
# ./nginx            启动
# ./nginx -s stop       停止
# ./nginx -s reload     重启





你可能感兴趣的:(linux)