1、官网下载nginx源码包
http://nginx.org/download/nginx-1.8.1.tar.gz
2、上传到opt目录,解压
cd /opt
tar -zxvf nginx-1.8.1.tar.gz
3、进入目录,编译安装
cd nginx-1.8.1
./configure
make & make install
4、编译安装时,如果报错提示gcc、glibc等,就是需要安装升级gcc编译工具
(1)升级安装系统编译工具
yum install -y gcc* yum -y install -y pcre* yum -y install -y openssl*
5、修改nginx配置
cd /usr/local/nginx/conf/
vim nginx.conf
worker_processes 1; events { worker_connections 1024; } http { include mime.types; default_type application/octet-stream; sendfile on; keepalive_timeout 65; upstream WebServers{ server 192.168.1.1; #没有设定权重,因此两台后端服务器将机会均等地接受请求 server 192.168.1.2; } server { listen 80; server_name localhost; location / { root html; index index.html index.htm; proxy_pass http://WebServers; } error_page 500 502 503 504 /50x.html; location = /50x.html { root html; } } }
6、启动nginx
cd /usr/local/nginx/sbin
./nginx -s reload #重新加载nginx配置
7、浏览器访问nginx
ip:80 #80是nginx默认端口号,能访问到nginx首页代表nginx安装启动成