1、安装依赖包
yum -y install gcc gcc-c++ autoconf automake
yum -y install zlib* openssl*
yum -y install pcre*
2、下载nginx
复制nginx-1.16.0.tar.gz 到/usr/local/soft 下
加压 tar -zxvf nginx-1.16.0.tar.gz
3、安装nginx
cd nginx-1.16.0
# 查看配置参数
./configure --help
#配置参数 --prefix安装目录 , 后面2个是http相关模块
./configure --prefix=/usr/local/nginx --with-http_stub_status_module --with-http_ssl_module
#编译并安装
make && make install
安装成功后会出现以下日志:
Configuration summary
+ using system PCRE library
+ using system OpenSSL library
+ md5: using OpenSSL library
+ sha1: using OpenSSL library
+ using system zlib library
nginx path prefix: "/usr/local/nginx"
nginx binary file: "/usr/local/nginx/sbin/nginx"
nginx configuration prefix: "/usr/local/nginx/conf"
nginx configuration file: "/usr/local/nginx/conf/nginx.conf"
nginx pid file: "/usr/local/nginx/logs/nginx.pid"
nginx error log file: "/usr/local/nginx/logs/error.log"
nginx http access log file: "/usr/local/nginx/logs/access.log"
nginx http client request body temporary files: "client_body_temp"
nginx http proxy temporary files: "proxy_temp"
nginx http fastcgi temporary files: "fastcgi_temp"
nginx http uwsgi temporary files: "uwsgi_temp"
nginx http scgi temporary files: "scgi_temp"
4、测试是否安装成功
cd /usr/local/nginx
.sbin/nginx -v
5、修改配置文件
vim conf/nginx.conf 修改IP
server {
listen 80;
server_name 192.168.8.107; #修改IP
#charset koi8-r;
#access_log logs/host.access.log main;
location / {
root html;
index index.html index.htm;
}
....
6、启动nginx
启动nginx: ./sbin/nginx
/usr/local/nging/sbin/nginx -s reload #重新载入配置文件
/usr/local/nging/sbin/nginx -s reopen #重启nginx
/usr/local/nging/sbin/nginx -s stop #停止nginx
查看进程:ps -ef | grep nginx
访问: http://192.168.8.107:80 , 出现nginx页面,则nginx正常。
7、配置负载均衡
修改配置文件nginx.conf
添加upstram模块, 修改location ,加入proxy_pass
# 负载均衡
upstream myserver {
server 192.168.8.107:8080 weight=1;
server 192.168.8.107:8081 weight=1;
}
server {
listen 80;
server_name 192.168.8.107;
#charset koi8-r;
#access_log logs/host.access.log main;
location / {
proxy_pass http://myserver ;
}
#location / {
# root html;
# index index.html index.htm;
#}
......
}