还会补充
[root@staticserver ~]# yum -y install gcc gcc-c++ pcre-devel openssl-devel
安装nginx
[root@staticserver ~]# tar -xf nginx-1.26.1.tar.gz
[root@staticserver ~]# ls
[root@staticserver ~]# cd nginx-1.26.1/也可以写 ./configure --prefix=/usr/local/nginx--user=nginx--group=nginx --with-http_ssl_module --with-http_stub_status_module --with-http_realip_module --with-stream
[root@staticserver ~]# useradd -s /bin/nologin -M nginx
一、nginx反向代理
1、动态服务器 后端服务器 对标Java服务器
1. 修改index.html文件,并且发布web服务
[root@git ~]# echo "this is java web server" > /usr/local/nginx/html/index.html
[root@git ~]# /usr/local/nginx/sbin/nginx
[root@git ~]# /usr/local/nginx/sbin/nginx -s reload
2. 使用curl访问当前目录
[root@git ~]# curl git
this is java web server
2、启动静态服务器(代理服务器)
要求使用128主机代理134,当用户访问128时,128不响应,而是134主机响应
使用128主机nginx反向代理134的服务器
nginx代理其他服务器时,不需要对方同意,更加方便了模块化操作,如果代理一个服务器,双方都需要同意
1. 启动服务
[root@tomcat ~]# echo "this is static server" > /usr/local/nginx/html/index.html
[root@tomcat ~]# /usr/local/nginx/sbin/nginx -s reload
[root@tomcat ~]# ps -aux | grep nginx
[root@tomcat ~]# curl tomcat
this is static server
[root@tomcat ~]# curl 192.168.8.134
this is java web server
2. 修改配置文件 /usr/local/nginx/conf/nginx.conf
location proxy_pass 协议 域名 端口
[root@tomcat ~]# vim /usr/local/nginx/conf/nginx.conf
[root@tomcat ~]# /usr/local/nginx/sbin/nginx -s reload
3、设置黑名单和白名单
1. 源码编译安装
[root@allowdeny ~]# scp -r root@192.168.8.128:~/nginx-1.26.1.tar.gz ./
[root@allowdeny ~]# yum -y install gcc gcc-c++ pcre-devel openssl-devel
[root@allowdeny ~]# tar -zxvf nginx-1.26.1.tar.gz
[root@allowdeny ~]# cd nginx-1.26.1/
[root@allowdeny nginx-1.26.1]# ./configure --prefix=/usr/local/nginx --user=nginx --group=nginx --with-http_ssl_module --with-http_stub_status_module --with-http_realip_module --with-stream
[root@allowdeny nginx-1.26.1]# make && make install
[root@allowdeny nginx-1.26.1]# useradd -s /bin/nologin -M nginx
[root@allowdeny nginx-1.26.1]# /usr/local/nginx/sbin/nginx
2. 修改index.html
[root@allowdeny nginx-1.26.1]# echo "you are luckly" > /usr/local/nginx/html/index.html
[root@allowdeny nginx-1.26.1]# curl allowdeny
you are luckly
[root@git ~]# curl 192.168.8.136
you are luckly
[root@tomcat ~]# curl 192.168.8.136
you are luckly
3. 设置除了134主机可以访问,其他主机都不可以访问
server模块中设置 allow允许 deny禁止 可以对ip生效,也可以对网段生效
[root@allowdeny nginx-1.26.1]# vim /usr/local/nginx/conf/nginx.conf
[root@allowdeny nginx-1.26.1]# /usr/local/nginx/sbin/nginx -s reload