[root@itlaoxin163 ~]# cd !$
cd /usr/local/src/
[root@itlaoxin163 src]# pwd
/usr/local/src
[root@itlaoxin163 src]# cd nginx-1.8.0/
[root@itlaoxin163 nginx-1.8.0]# pwd
/usr/local/src/nginx-1.8.0
3)开始编译:
./configure --prefix=/usr/local/nginx --with-http_dav_module --with-http_stub_status_module --with-http_addition_module --with-http_sub_module --with-http_flv_module --with-http_mp4_module
对参数的解释:
参数:
–with-http_dav_module 启用ngx_http_dav_module支持(增加PUT,DELETE,MKCOL:创建集合,COPY和MOVE方法)默认情况下为关闭,需编译开启
–with-http_stub_status_module 启用ngx_http_stub_status_module支持(获取nginx自上次启动以来的工作状态)
–with-http_addition_module 启用ngx_http_addition_module支持(作为一个输出过滤器,支持不完全缓冲,分部分响应请求)
–with-http_sub_module 启用ngx_http_sub_module支持(允许用一些其他文本替换nginx响应中的一些文本)
–with-http_flv_module 启用ngx_http_flv_module支持(提供寻求内存使用基于时间的偏移量文件)
–with-http_mp4_module 启用对mp4文件支持(提供寻求内存使用基于时间的偏移量文件)
4)安装
[root@itlaoxin163 nginx-1.8.0]# make && make install
5) 生成运行nginx的用户
[root@itlaoxin163 nginx-1.8.0]# useradd -u 8000 -s /sbin/nologin nginx
[root@itlaoxin163 nginx-1.8.0]# id !$
id nginx
uid=8000(nginx) gid=8000(nginx) 组=8000(nginx)
[root@itlaoxin163 nginx-1.8.0]#
6)启动nginx
如果你不知道nginx配置文件和启动脚本在哪,可以搜一下
[root@itlaoxin163 ~]# find / -name nginx.conf
/usr/local/nginx/conf/nginx.conf
[root@itlaoxin163 ~]# /usr/local/nginx/sbin/nginx
[root@itlaoxin163 ~]# netstat -antup |grep 80
tcp 0 0 0.0.0.0:80 0.0.0.0:* LISTEN 9327/nginx: master
[root@itlaoxin163 ~]#
7) 查看nginx执行效果
[root@itlaoxin163 ~]# systemctl stop firewalld.service
[root@itlaoxin163 ~]# curl -I 127.0.0.1
HTTP/1.1 200 OK
Server: nginx/1.8.0
Date: Fri, 02 Apr 2021 00:55:30 GMT
Content-Type: text/html
Content-Length: 612
Last-Modified: Fri, 02 Apr 2021 00:46:51 GMT
Connection: keep-alive
ETag: “6066697b-264”
Accept-Ranges: bytes
2. 配置nginx成为分发器
1)先备份
[root@itlaoxin163 ~]# cd /usr/local/nginx/c
client_body_temp/ conf/
[root@itlaoxin163 ~]# cd /usr/local/nginx/c
client_body_temp/ conf/
[root@itlaoxin163 ~]# cd /usr/local/nginx/conf/
[root@itlaoxin163 conf]# cp nginx.conf nginx.conf.bak
[root@itlaoxin163 conf]#
2) 把nginx设置成分发器,实现动静分离
为了方便大家复制:
location / {
root html;
index index.html index.htm;
if ( r e q u e s t u r i ∗ h ˙ t m l request_uri ~* \.html requesturi ∗h˙tml){
proxy_pass http://htmlservers;
}
if ( r e q u e s t u r i ∗ p ˙ h p request_uri ~* \.php requesturi ∗p˙hp){
proxy_pass http://phpservers;
}
proxy_pass http://picservers;
3) 定义负载均衡设备的IP
在nginx配置文件最后一行}前添加一下内容:
upstream htmlservers {
server 192.168.1.162:80;
server 192.168.1.164:80;
}
upstream phpservers{
server 192.168.1.162:80;
server 192.168.1.164:80;
}
upstream picservers {
server 192.168.1.162:80;
server 192.168.1.164:80;
}
4) 测试配置文件是否ok
[root@itlaoxin163 conf]# /usr/local/nginx/sbin/nginx -t
nginx: the configuration file /usr/local/nginx/conf/nginx.conf syntax is ok
nginx: configuration file /usr/local/nginx/conf/nginx.conf test is successful
[root@itlaoxin163 conf]#
5) 重启nginx
[root@itlaoxin163 conf]# /usr/local/nginx/sbin/nginx -s reload
在ITlaoxin62服务器和63服务器上进行配置
ITlaoxin62:
配置web服务器:
[root@ITlaoxin162 html]# yum install httpd php -y
生成静态测试文件:
[root@ITlaoxin162 html]#echo 192.168.1.162 > /var/www/html/index.html
最后
不知道你们用的什么环境,我一般都是用的Python3.6环境和pycharm解释器,没有软件,或者没有资料,没人解答问题,都可以免费领取(包括今天的代码),过几天我还会做个视频教程出来,有需要也可以领取~
给大家准备的学习资料包括但不限于:
Python 环境、pycharm编辑器/永久激活/翻译插件
python 零基础视频教程
Python 界面开发实战教程
Python 爬虫实战教程
Python 数据分析实战教程
python 游戏开发实战教程
Python 电子书100本
Python 学习路线规划
网上学习资料一大堆,但如果学到的知识不成体系,遇到问题时只是浅尝辄止,不再深入研究,那么很难做到真正的技术提升。
一个人可以走的很快,但一群人才能走的更远!不论你是正从事IT行业的老鸟或是对IT行业感兴趣的新人,都欢迎加入我们的的圈子(技术交流、学习资源、职场吐槽、大厂内推、面试辅导),让我们一起学习成长!