First, install gcc
yum install gcc-c++ -y
Second, the dependent libraries required nginx
yum -y install zlib-devel openssl-devel pcre-devel
Third, if installed an older version, uninstall.
View: find -name nginx
Uninstall: yum remove nginx
Fourth, download the source code and extract nginx. (Go to the official website to download the source code, the following is the official link)
wget -c http://nginx.org/download/nginx-1.6.2.tar.gz
tar -zxvf nginx-1.6.2.tar.gz
mv nginx-1.6.2 nginx
cd nginx
./configure --user=nginx --group=nginx --prefix=/usr/local/nginx
--with-http_addition_module
--with-http_flv_module --with-http_gzip_static_module
--with-http_realip_module --with-http_ssl_module
--with-http_stub_status_module --with-http_sub_module
--with-http_dav_module
Note: --with option that starts here nginx module comes, what needs to be added, the default is not installed,
make
make install
Fifth, the establishment nginx users and user groups
groupadd -r nginx
-s useradd / sbin / nologin -g -r nginx nginx
cd nginx directory to see if I can start
sbin / nginx # If there is no error, indicating ok
Ps it again, ps ax | grep nginx, see the following, indicating the ok
2537 Ss 0:00 nginx: Master Process sbin / nginx?
2538 0:00 nginx S: Process worker?
nginx after the start, there will be a master process and multiple worker processes. master process is primarily used to manage the worker process, comprising: receiving a signal from the outside, a signal is sent to each worker process, monitor the operation status of worker processes, when the worker process exits (exceptional circumstances), it will automatically re-start a new worker process .
View installed nginx version:
sbin / nginx -v
view the installation compiler options:
sbin / nginx -V
Sixth, let's start to configure nginx, and reverse proxy, edit the configuration file nginx.conf
vim /usr/local/nginx/conf/nginx.conf
user nginx nginx; # This is the user running nginx
worker_processes 2; # Set nginx services worker child processes, such as Set 2:
error_log logs / error.log; # # removed in front of the recording nginx error log, easy inspection bug:
pid logs / nginx.pid; #nginx position of pid
{Events
worker_connections 1024; # each process allows the maximum number of connections,
}
http {
include mime.types;
default_type application/octet-stream;
# # Get rid of the following, which is the log configuration:
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; # log storage position
# This is very important, many small partners asked me "load balancing configuration at first glance, why can not I access the configuration of it," here is the configuration of the upstream load balancing, of course, have more than two called load, ip69 me here and 68 They are
# With apache, maybe you is tomcat, it does not matter, as according to this configuration possible,
upstream proxy_test {
server 192.168.4.69:80 weight = 1; # if you want to test, you want to put into your own back-end proxy ip here
server 192.168.4.68:80 weight=1;
#ip_hash; # when the load by more than two to hash ip solve the problem of session, one on the other hash.
}
This is the configuration server segment
server {
listen 80;
server_name www.test.com; # domain name you want to access, I use the test domain if there are multiple, separated by commas
charset utf8;
location / {
proxy_pass http: // proxy_test; # proxy_test here is the name above the load, mapped to the proxy server, it can be a plus ip port, or url
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
}
}
Save and exit!
Graceful Restart nginx: nginx -s reload # load just joined configuration.
Configuring nginx boot from the start
vim /etc/rc.d/rc.local