13_ build Nginx server configuration web authentication, based virtual hosting, ssl web hosting

Official yum Source:
[Nginx]
name = Nginx the repo
BaseURL = HTTP: //nginx.org/packages/centos/$releasever/$basearch/
gpgcheck = 0
Enabled =. 1

PC7
1. Installation Nginx
] # yum the install Nginx -Y
] nginx #
] -V # nginx
nginx Version: nginx / 1.16.1
] # netstat -anptu | grep nginx
] # curl http://10.10.11.10

physical machine:
Firefox http://10.10.11.10/

2. configure user authentication
] # cd /etc/nginx/conf.d
conf.d] # cp -p default.conf default.conf.bak
conf.d] # vim default.conf
...
server_name localhost;
     auth_basic "the Input Password";
     auth_basic_user_file " / usr / local / nginx / Pass ";
...
the conf.d] # yum the install the httpd -Y-Tools
the conf.d] # the htpasswd -C /etc/nginx/conf.d/pass TOM1
the conf.d] # # append the htpasswd /etc/nginx/conf.d/pass tom2 users do not use the -c option
conf.d] # CAT /etc/nginx/conf.d/pass
TOM1: $ APR1 $ UL9KCacj $ OieKdhwxB6QXk48g8aq80 /
tom2: $ APR1 $ BLccaaL7 $ sVlr9y7YfGVaDQEGWNI5s1
conf.d] # nginx -s reload

physical machine test:
] # Firefox http://10.10.11.10
(to enter account, password, pay attention to clear your browser cache)

3. based virtual hosting
conf.d] # vim default.conf
www.a.com configured user authentication
Server {
    the listen 80;
    server_name www.a.com;
    auth_basic "the Input Password";
    auth_basic_user_file "/ usr / local / Nginx / Pass";
       
    LOCATION / {
        the root / usr / Share / Nginx / HTML;
        index.html index.htm index;
    }
 
www.b.com not user authentication
Server {
    the listen 80;
    server_name www.b.com;
 
    LOCATION / {
        the root / usr / Share / Nginx / WWW;
        index index.html index.htm ;
    }
] # mkdir / usr / local / Nginx / WWW
] # echo "WWW"> /usr/local/nginx/www/index.html
] # -s reload Nginx

physical machine test:
] # Vim / etc / the hosts
10.10 www.a.com www.b.com .11.10
] # Firefox http://www.a.com (enter a user name and password to access)
] # Firefox http://www.b.com;

4.SSL Web Hosting
] CD # / etc / Nginx /
Nginx] # genrsa-OpenSSL> // generates a secret key cert.key
nginx # openssl req -new -x509 -key cert.key > cert.pem # generate a certificate
nginx] # ls
cert.pem ... cert.key
Nginx] # Vim the conf.d / default.conf
 Server {
    the listen SSL 443; # to change
    server_name www.b.com;
 
    ssl_certificate cert.pem;
    ssl_certificate_key cert.key;
 
    ssl_session_cache Shared: the SSL : 1M;
    ssl_session_timeout 5m;
 
    ssl_ciphers to HIGH: aNULL: the MD5;!!
    ssl_prefer_server_ciphers ON;
 
    LOCATION / {
        the root / usr / Share / Nginx / WWW;
        index index.html index.htm;
        }
    }
] # -s reload Nginx

physical access to the machine :
] # vim / etc / hosts
10.10.11.10 www.a.com www.b.com
] after firefox https://www.b.com # # certificate can be trusted access

Guess you like

Origin www.cnblogs.com/luwei0915/p/12148665.html