1、安装nginx
在nginx主机(10.1.236.54)上操作:
1、下载nginx安装包
wget http://nginx.org/download/nginx-1.8.0.tar.gz
2、解压
tar -zxvf nginx-1.8.0.tar.gz
3、进入解压后的nginx目录
cd nginx-1.8.0
4、安装依赖软件包
yum install -y pcre pcre-devel openssl openssl-devel gcc gcc gcc-c++ ncurses-devel perl
5、编译前准备
#将这句注释掉 取消Debug编译模式,在179行
vim auto/cc/gcc
#CFLAGS=”$CFLAGS -g”
6、配置
./configure —prefix=/usr/local/nginx —with-http_stub_status_module —with-http_ssl_module
7.编译
make
8.编译安装
make install
2、安装httpd工具
在nginx主机(10.1.236.54)上操作:
yum install httpd -y
3、配置访问密码
在nginx主机(10.1.236.54)上操作:
htpasswd -b -c /usr/local/nginx/conf/passwd.db raoyitest 123456
4、配置nginx
在nginx主机(10.1.236.54)上操作:
cp /usr/local/nginx/conf/nginx.conf /usr/local/nginx/conf/nginx.conf.bak
vi /usr/local/nginx/conf/nginx.conf
worker_processes 1;
events {
worker_connections 1024;
}
http {
include mime.types;
default_type application/octet-stream;
sendfile on;
keepalive_timeout 65;
server {
listen 80;
server_name ocdp54 10.1.236.54;
auth_basic "User Authentication";
auth_basic_user_file /usr/local/nginx/conf/passwd.db;
location / {
proxy_pass http://10.1.234.112:61310;
}
}
server {
listen 81;
server_name ocdp54 10.1.236.54;
auth_basic "User Authentication";
auth_basic_user_file /usr/local/nginx/conf/passwd.db;
location / {
proxy_pass http://10.1.236.54:18080;
}
}
}
5、启动nginx
在nginx主机(10.1.236.54)上操作:
/usr/local/nginx/sbin/nginx
6、设置iptables(不需要启动iptables服务)
集群安装的时候关闭了iptables,这里不需要启动iptables
6.1、配置限制18080端口访问
在18080端口主机上执行:
1、在tcp协议中,禁止所有的ip访问本机的18080端口。
iptables -I INPUT -p tcp —dport 18080 -j DROP
2、允许nginx所在主机(10.1.236.54)访问本机的18080端口
iptables -I INPUT -s 10.1.236.54 -ptcp —dport 18080 -j ACCEPT
6.2、配置限制61310端口访问
在61310端口主机上执行:
1、在tcp协议中,禁止所有的ip访问本机的61310端口。
iptables -I INPUT -p tcp —dport 61310 -j DROP
2、允许nginx所在主机(10.1.236.54)访问本机的61310端口
iptables -I INPUT -s 10.1.236.54 -ptcp —dport 61310 -j ACCEPT
7、访问
访问原来的61310将无法访问:
访问方法:通过nginx中配置的主机和端口及密码进行访问:
输入密码后方可进行访问
8、恢复
8.1、恢复iptables规则
在18080端口主机上执行:
查看:
iptables -nL —line-number
删除(执行两次命令):
iptables -D INPUT 1
在61310端口主机上执行:
iptables -nL —line-number
删除(执行两次命令):
iptables -D INPUT 1
8.2、停止nginx
/usr/local/nginx/sbin/nginx -s stop