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

2.web服务器的默认访问目录为/var/www/html
默认发布内容为default‘s page

下载nginx服务并启用:
[root@localhost ~]# dnf install nginx
[root@localhost ~]# systemctl enable --now nginx.service
修改默认发布路径:
[root@localhost ~]# vim /etc/nginx/nginx.conf
 server {
        listen       80;
        listen       [::]:80;
        server_name  _;
        #root         /usr/share/nginx/html;
        root          /var/www/html;
        index           index.html;
[root@localhost ~]# echo "defult's page" > /var/www/html/index.html
[root@localhost ~]# curl 172.25.254.100
defult's page


3.站点news.timinglee.org默认发布目录为
/var/www/virtual/timinglee.org/news
默认发布内容为 news.timinglee.org

[root@localhost ~]# cd /etc/nginx/conf.d/
编写文件:
[root@localhost conf.d]# vim vhosts.conf
server{
        listen 80;
        server_name news.timinglee.org;
        root /var/www/virtual/timinglee.org/news;
        index               index.html;
}
创建目录:
[root@localhost conf.d]# mkdir -p /var/www/virtual/timinglee.org/news
输出重定向:
[root@localhost conf.d]# echo "news.timinglee.org" > /var/www/virtual/timinglee.org/news/index.html
重启:
[root@localhost conf.d]# systemctl restart nginx.service
解析:
[root@localhost conf.d]# vim /etc/hosts
172.25.254.100 server100.timinglee.org news.timinglee.org 
测试:
[root@localhost conf.d]# curl news.timinglee.org
news.timinglee.org
4.站点login.timinglee.org在被访问时必须强制走加密协议,其默认发布目录为/var/www/virtual/timinglee.org/login
默认发布内容为login.timinglee.org

创建目录:
[root@localhost nginx]# mkdir -p /etc/nginx/certs
认证:
[root@localhost nginx]# openssl req -newkey rsa:2048 -nodes -sha256 -keyout /etc/nginx/certs/timinglee.org.key -x509 -days 356 -out /etc/nginx/certs/timinglee.org.crt
Country Name (2 letter code) [XX]:CN
State or Province Name (full name) []:ShanXi
Locality Name (eg, city) [Default City]:Xi'an
Organization Name (eg, company) [Default Company Ltd]:timinglee
Organizational Unit Name (eg, section) []:web
Common Name (eg, your name or your server's hostname) []:www.easylee.org
Email Address []:lee@easylee.org
强制加密
[root@localhost conf.d]# vim vhosts.conf
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/www/virtual/timinglee.org/login;
        index index.html;
}
创建目录:
[root@localhost conf.d]# mkdir -p /var/www/virtual/timinglee.org/login
[root@localhost conf.d]# echo "login.timinglee.org"> /var/www/virtual/timinglee.org/login/index.html
添加解析:
[root@localhost nginx]# vim /etc/hosts
172.25.254.100 server100.timinglee.org news.timinglee.org www.timinglee.org login.timinglee.org
[root@localhost 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>

测试可在浏览器中进行

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值