您的位置:首页 > 理论基础 > 计算机网络

[原创] Nginx 添加授权访问 使用 httpd-tools

2017-03-28 17:27 405 查看

安装 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


内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  nginx 密码 iptables