Nginx服务器搭建步骤
(1)添加yum源
cat > /etc/yum.repos.d/nginx.repo << ENF
[nginx]
name=nginx repo
baseurl=http://nginx.org/packages/centos/6/x86_64/
gpgcheck=0
enabled=1
(2)yum安装
yum install nginx
(3)nginx.confg配置文件更新
vi /etc/nginx/nginx.conf
user nginx; worker_processes 4; error_log /var/log/nginx/error.log warn; pid /var/run/nginx.pid; worker_rlimit_nofile 51200; events { use epoll; worker_connections 51200; multi_accept on; } http { include /etc/nginx/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"'; log_format access '$remote_addr [$time_local] "$server_name $request" ' '$connection_requests $request_length $bytes_sent $status "$http_referer" ' '"$http_user_agent" "$http_x_forwarded_for" "$upstream_addr $upstream_status $upstream_response_time" $request_time' ; access_log /var/log/nginx/access.log main; server_names_hash_bucket_size 128; client_header_buffer_size 32k; large_client_header_buffers 4 32k; client_max_body_size 50m; client_body_buffer_size 128k; sendfile on; tcp_nopush on; keepalive_timeout 45; server_tokens off; tcp_nodelay on; proxy_set_header Host $host; proxy_set_header X-Real-IP $remote_addr; proxy_set_header REMOTE-HOST $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; #gzip on; include /etc/nginx/conf.d/*.conf; } |
删除conf.d/default.conf默认配置文件
#cd /etc/nginx
[root@dopapp8 nginx]# rm -f /etc/nginx/conf.d/default.conf
(4)编辑/etc/nginx/conf.d/cnInterface.conf 配置文件
vi /etc/nginx/conf.d/cnInterface.conf
server { listen 80; server_name 10.251.3.72; #charset koi8-r; access_log /var/log/nginx/access.log access; location /cnInterface { proxy_pass http://cnInterface; } } |
(5)编辑/etc/nginx/conf.d/upstream.conf 配置文件
[root@dopapp8 conf.d]# cat upstream.conf upstream cnInterface { server 10.251.3.76:8580 weight=6 max_fails=2 fail_timeout=2s; server 10.251.3.77:8580 weight=6 max_fails=2 fail_timeout=2s; } |
(6)启动nginx
验证配置文件:[root@dopapp8 nginx]# /usr/sbin/nginx -t
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful
启动nginx:[root@dopapp8 nginx]# /usr/sbin/nginx
(7)验证NGINX负载运行状态
1.负载均衡访问页面
2. nginx进程