当前位置:首页 > Web开发 > 正文

密码访问) ]# firefox ; 4.SSL虚拟主机 ]# cd /etc/nginx/ nginx]# opens

2024-03-31 Web开发

官方yum源:
[nginx]
name=nginx repo
baseurl=http://nginx.org/packages/centos/$releasever/$basearch/
gpgcheck=0
enabled=1

pc7
1. 安置nginx
]# yum -y install nginx
]# nginx
]# nginx -V
nginx version: nginx/1.16.1
]# netstat -anptu | grep nginx
]# curl

物理机:
firefox

2. 配置用户认证
]# cd /etc/nginx/conf.d
conf.d]# cp -p default.conf default.conf.bak
conf.d]# vim default.conf
...
server_name  localhost;
     auth_basic "Input Password";
     auth_basic_user_file "/usr/local/nginx/pass";
...
conf.d]# yum -y install httpd-tools
conf.d]# htpasswd -c /etc/nginx/conf.d/pass tom1
conf.d]# htpasswd /etc/nginx/conf.d/pass tom2    # 追加用户,不使用-c选项
conf.d]# cat /etc/nginx/conf.d/pass
tom1:$apr1$UL9KCacj$OieKdhwxB6QXk48g8aq80/
tom2:$apr1$BLccaaL7$sVlr9y7YfGVaDQEGWNI5s1
conf.d]# nginx -s reload

物理机测试:
]# firefox
(要输入账户、暗码,注意断根浏览器缓存)

3. 基于域名的虚拟主机
conf.d]# vim default.conf
配置了用户认证
server {
    listen       80;
    server_name  ;
    auth_basic "Input Password";
    auth_basic_user_file "/usr/local/nginx/pass";
       
    location / {
        root   /usr/share/nginx/html;
        index  index.html index.htm;
    }
 
未配置用户认证
server {
    listen       80;
    server_name  ;
 
    location / {
        root   /usr/share/nginx/www;
        index  index.html index.htm;
    }
]# mkdir /usr/local/nginx/www
]# echo "www" > /usr/local/nginx/www/index.html
]# nginx -s reload

物理机测试:
]# vim /etc/hosts
10.10.11.10 www.b.com
]# firefox (输入用户名,暗码访谒)
]# firefox ;

4.SSL虚拟主机
]# cd /etc/nginx/
nginx]# openssl genrsa > cert.key //生成私钥
nginx# openssl req -new -x509 -key cert.key > cert.pem # 生成证书
nginx]# ls
cert.key  cert.pem ...
nginx]# vim conf.d/default.conf
 server {
    listen       443 ssl;            # 要改
    server_name  ;
 
    ssl_certificate      cert.pem;
    ssl_certificate_key  cert.key;
 
    ssl_session_cache    shared:SSL:1m;
    ssl_session_timeout  5m;
 
    ssl_ciphers  HIGH:!aNULL:!MD5;
    ssl_prefer_server_ciphers  on;
 
    location / {
        root   /usr/share/nginx/www;
        index  index.html index.htm;
        }
    }
]# nginx -s reload

物理机访谒:
]# vim /etc/hosts
10.10.11.10  
]# firefox https://www.b.com     #信任证书后可以访谒

13_搭建Nginx处事器、配置网页认证、基于域名的虚拟主机、ssl虚拟主机

标签:

原文地点:https://www.cnblogs.com/luwei0915/p/12148665.html

温馨提示: 本文由Jm博客推荐,转载请保留链接: https://www.jmwww.net/file/web/32295.html