centos7安装nginx

官网下载nginx

下载地址 http://nginx.org/en/download.html
选择 nginx-1.13.6下载最新版本

上传

rz -b 选择下载好的nginx上传到linux

解压到 /usr/local/src目录

tar -zxvf /opt/software/nginx-1.13.6.tar.gz -C /usr/local/src

安装

./configure –prefix=/usr/local/nginx
安装并指定安装到的目录

错误修改

提示下面的错误,是因为缺少必要的依赖
./configure: error: C compiler cc is not found

需要安装依赖gcc,pcre-devel,openssl,openssl-devel
yum install -y gcc pcre-devel openssl openssl-devel

如果装了gcc还不行的话可能就是需要安装gcc-c++
yum install gcc-c++ -y

安装

./configure --prefix=/usr/local/nginx  
上面的命令意思是编译 编译完成之后需要安装
make install 或者make进行安装

测试是否安装成功

启动nginx 在usr/local/nginx/bin目录下,有一个ngnix,执行这个可执行文件就能启动
查看端口是否有nginx进程 netstat -ntlp |grep 80
能够看到启动了有关的nginx的80进程

附加:可以修改配置文件,设置反向代理和负载均衡。利用keepalived实现nginx的高可用性(相当于两个nginx)。

httpd

安装httpd
有关httpd的操作

systemctl start httpd.service #启动
systemctl stop httpd.service #停止
systemctl restart httpd.service #重启
systemctl enable httpd.service #开机启动
systemctl disable httpd.service #开机不启动
systemctl status httpd.service

修改端口,首先停止httpd服务,在文件中/etc/httpd/config/httpd.conf 将他的Listen监听的端口改为8080

动静分离

修改nginx的配置文件,在其中加上方向代理。~表示的是大小写敏感。符合后面的都是动态资源,要转发的对应的proxy_pass所在的服务器。

location ~ .*.(jsp|do|action) {
proxy_cache cache_one;
proxy_cache_valid 200 304 302 5d;
proxy_cache_valid any 5d;
proxy_cache_key ‘host: server_portrequesturi;addheaderXCache upstream_cache_status from $host’;
proxy_pass 192.168.88.200:8080;
#所有静态文件直接读取硬盘
# root /var/lib/tomcat7/webapps/JieLiERP/WEB-INF ;
expires 30d; #缓存30天
}

负载均衡

链接多台tomcats,由ngnix轮流去请求,在http{}中加入。weight是权重,如果机器性能比较好可以适当增加权重。

upstream tomcats{
    server server1:3128 weight=1;
    server server2:3128 weight=1;
}
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章