[root@server ~]# mkdir /www/openlab
[root@server ~]# echo 'welcom to openlab' > /www/openlab/index.html [root@server ~]# vim /etc/nginx/nginx.conf server { listen 80; server_name www.openlab.com; root /www/openlab; } [root@server ~]# systemctl start nginx
[root@server ~]# mkdir /www/openlab/file [root@server ~]# echo 'data' > /www/openlab/data/index.html [root@server ~]# vim /etc/nginx/nginx.conf
server { listen 80; server_name www.openlab.com; root /www/openlab; location /data {
alias /www/openlab/file; index index.html index.htm; }
} [root@server ~]# systemctl restart nginx
创建学生信息子网站www.openlab.com/student
[root@server ~]# mkdir /www/openlab/student [root@server ~]# echo 'student' > /www/openlab/student/index.html [root@server ~]# useradd song [root@server ~]# passwd song
[root@server ~]# useradd tian [root@server ~]# passwd tian
[root@server ~]# htpasswd /etc/nginx/passwd song [root@server ~]# htpasswd /etc/nginx/passwd tian
[root@server ~]# vim /etc/nginx.conf server { listen 80; server_name www.openlab.com; root /www/openlab; location /data { alias /www/openlab/data; index index.html index.htm; }
location /student { alias /www/openlab/student; index index.html index.htm; auth_basic "Please input password"; auth_basic_user_file /etc/nginx/passwd; } } [root@server ~]# systemctl restart nginx
创建缴费子网站www.openlab.com/money
[root@server ~]# mkdir /www/openlab/money [root@server ~]# echo 'money' > /www/openlab/money/index.html [root@server ~]# openssl genrsa -aes128 2048 > /etc/nginx/money.key Generating RSA private key, 2048 bit long modulus (2 primes) ....................+++++ ...................................+++++ e is 65537 (0x010001) Enter pass phrase:Verifying - Enter pass phrase: [root@server ~]# openssl req -utf8 -new -key /etc/nginx/money.key -x509 -days 365 -out /etc/nginx/money.crt Enter pass phrase for /etc/nginx/money.key: You are about to be asked to enter information that will be incorporated into your certificate request.What you are about to enter is what is called a Distinguished Name or a DN. There are quite a few fields but you can leave some blank For some fields there will be a default value,If you enter '.', the field will be left blank.----- Country Name (2 letter code) [AU]:86 State or Province Name (full name) [SomeState]:ningxia Locality Name (eg, city) []:yingchuan Organization Name (eg, company) [Internet Widgits Pty Ltd]:openlab Organizational Unit Name (eg, section) []:RHCE Common Name (e.g. server FQDN or YOUR name) []:server Email Address []:123 [root@server ~]# cd /etc/nginx [root@server nginx]# cp money.key money.key.org
[root@server nginx]# openssl rsa -in money.key.org -out money.key Enter pass phrase for money.key.org:
writing RSA key [root@server nginx]# vim /etc/nginx/nginx.conf server { listen 80; server_name www.openlab.com; root /www/openlab; location /file { alias /www/openlab/file; index index.html index.htm; } location /student { alias /www/openlab/student; index index.html index.htm; auth_basic "Please input password"; auth_basic_user_file /etc/nginx/passwd; } } server { listen 443 ssl http2;server_name www.openlab.com; location /money { alias /www/openlab/money; index index.html index.htm; } ssl_certificate "/etc/nginx/money.crt"; ssl_certificate_key "/etc/nginx/money.key"; } [root@server nginx]# systemctl restart nginx