unit4.web服务的部署及高级优化方案
1.
搭建web服务器要求如下:
1.web服务器的主机ip:172.25.254.100
2.web服务器的默认访问目录为/var/www/html
默认发布内容为default‘s page
3.站点news.timinglee.org默认发布目录为/var/www/virtual/timinglee.org/news
默认发布内容为 news.timinglee.org
4.站点login.timinglee.org在被访问时必须强制走加密协议,其默认发布目录为/var/www/virtual/timinglee.org/login
默认发布内容为login.timinglee.org
1.
[root@server ~]# ifconfig
ens160: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
inet 192.168.187.131 netmask 255.255.255.0 broadcast 192.168.187.255
2.
[root@server ~]# vim /etc/nginx/nginx.conf
...
server {
listen 80;
listen [::]:80;
server_name _;
root /var/www/html;
...
:wq
[root@server ~]# systemctl restart nginx.service
[root@server ~]# mkdir /var/www/html/index.html
测试:
[root@server ~]# curl 192.168.187.131
<html>
<head><title>404 Not Found</title></head>
<body>
<center><h1>404 Not Found</h1></center>
<hr><center>nginx/1.20.1</center>
</body>
</html>
3.
[root@server ~]# vim /etc/nginx/conf.d/vhost.conf
server {
listen 80;
server_name news.timinglee.org;
root /var/www/virtual/timinglee.org/news;
index index.html;
}
server {
listen 80;
server_name login.timinglee.org;
rewrite ^/(.*)$ https://login.timinglee.org/$1 permanent;
}
server {
listen 443 ssl;
server_name login.timinglee.org;
ssl_certificate "/etc/nginx/certs/timinglee.org.crt";
ssl_certificate_key "/etc/nginx/certs/timinglee.org.key";
root /var/wwwvirtual/timinglee.org/login;
index index.html;
}
...
:wq
[root@server ~]# vim /etc/hosts
192.168.187.131 news.timinglee.org login.timinglee.org
...
:wq
测试:
[root@server nginx]# curl login.timinglee.org
<html>
<head><title>301 Moved Permanently</title></head>
<body>
<center><h1>301 Moved Permanently</h1></center>
<hr><center>nginx/1.20.1</center>
</body>
</html>
4.
[root@server certs]# openssl req-newkey rsa:2048 -nodes -sha256 -keyout /etc/nginx/certs/timinglee.org.key -x509 -days 365 -out /etc/nginx/certs/timinglee.org.crt
Country Name (2 letter code) [XX]:cn
State or Province Name (full name) []:cn
Locality Name (eg, city) [Default City]:cn
Organization Name (eg, company) [Default Company Ltd]:cn
Organizational Unit Name (eg, section) []:cn
Common Name (eg, your name or your server's hostname) []:cn
Email Address []:cn
测试: