安装 nginx
yum install -y nginx
安装 iptables iptables-services
使用 iptables-services 管理配置文件
yum install -y iptables iptables-services
配置 iptables
# vi /etc/sysconfig/iptable
# 默认有22端口, 复制一行, 改为 nginx 端口即可.
-A INPUT -p tcp -m state --state NEW -m tcp --dport 80 -j ACCEPT
启动 iptables
service iptables start
安装 httpd-tools
# 生成密码
yum install -y httpd-tools
生成密码文件
htpasswd /etc/nginx/httpdwd nginx_user
配置 nginx
# vi /etc/nginx/nginx.conf
# 在 配置中添加 auth_basic 和 auth_bashc_user_file 即可
server {
listen 80 default_server;
listen [::]:80 default_server;
server_name _;
client_max_body_size 10K;
root /usr/share/nginx/html;
# 在这里添加授权配置
auth_basic "Username and Password are required";
auth_basic_user_file /etc/nginx/httpdwd;
# ... ...
}
启动 nginx
service nginx start
完