kkkkkk

[root@server100 ~]# vim /etc/nginx/nginx.conf
root  /var/www/html;
[root@server100 ~]# echo 172.25.254.100  >  /var/www/html/index.html
[root@server100 ~]# curl 172.25.254.100
172.25.254.100
[root@server100 ~]# mkdir -p /var/www/html
[root@server100 ~]# echo /var/www/html > /var/www/html/index.html
[root@server100 ~]# vim /var/www/html/test.html
[root@server100 ~]# vim /etc/nginx/nginx.conf
index test.html   index.html;
[root@server100 ~]# nginx  -t
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful
[root@server100 ~]# systemctl restart nginx.service

测试
[root@server100 html]# curl 172.25.254.100
default's page


[root@server100 ~]# cd /etc/nginx/conf.d/
[root@server100 conf.d]# vim  vhosts.conf

 server {
        listen 80;
        server_name news.timinglee.org;
        root /var/www/virtual/timinglee.org/news;
        index index.html;
}

[root@server100 conf.d]# systemctl restart nginx.service

[root@server100 ~]# nginx  -t
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful

[root@server100 ~]# mkdir -p /var/www/virtual/timinglee.org/news
[root@server100 ~]# echo news.timinglee.org > /var/www/virtual/timinglee.org/news/index.html

[root@server100 ~]# vim /etc/hosts

www.timinglee.org  news.timinglee.org  login.timinglee.org
测试

[root@server100 conf.d]# curl news.timinglee.org
news.timinglee.org

[root@server100 conf.d]# vim  vhosts.conf

server {
        listen 80;
        server_name login.timinglee.org;
        root /var/www/virtual/timinglee.org/login;
        index index.html;
}
[root@server100 conf.d]# systemctl restart nginx.service
root@server100 conf.d]#  mkdir -p /var/www/virtual/timinglee.org/login
[root@server100 conf.d]#  echo login.timinglee.org > /var/www/virtual/timinglee.org/login/index.html

[root@server100 ~]# nginx  -t
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful
[root@server100 conf.d]# systemctl restart nginx.service
测试
[root@server100 conf.d]# curl login.timinglee.org
login.timinglee.org


[root@server100 ~]# mkdir  /etc/nginx/certs

[root@server100 ~]# openssl req -newkey rsa:2048  -nodes -sha256  -keyout  /etc/nginx/certs/timinglee.org.key  -x509  -days 365  -out  /etc/nginx/certs/timinglee.org.crt
...+..............+...+....+.............................+....+..+...+................+.....+.+......+...+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*.......+...+...+.+.........+..+.......+...+..+.+......+.........+.........+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*.......+..+...+.............+...+..+....+...+..+......+...+....+...........+......+...+................+..............+.+.....+.+.....+...+.....................+.+.....+......+...+..........+............+.....+....+...+........+....+...........+...+....+..+...............+.+...+..+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
.+.+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*.+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*..+......+...+......+...+.......+...+......+............+.....+....+.....+................+..+...+.............+...........+...+.+..+...............+....+.........+..+...+....+..+......+.......+..+......+.......+........+.......+...+..+.............+..+.+.....+......+.+........+....+........+.......+..+.............+...........+.+...............+...+............+.....+...+...+.........+...+...+..........+.....+...+....+.....+..........+..+...+......+..........+.....+....+...+..+.+...........+....+.................+....+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
-----
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) [XX]:CN
State or Province Name (full name) []:Shannxi
Locality Name (eg, city) [Default City]:Xi'an
Organization Name (eg, company) [Default Company Ltd]:timinglee
Organizational Unit Name (eg, section) []:webserver
Common Name (eg, your name or your server's hostname) []:www.login.timinglee.org
Email Address []:admin@timinglee.org
[root@server100 ~]# 
[root@server100 ~]# ls  /etc/nginx/certs/
timinglee.org.crt  timinglee.org.key
[root@server100 ~]# vim  /etc/nginx/conf.d/vhosts.conf
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@server100 ~]# nginx  -t
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful
[root@server100 ~]# systemctl restart nginx.service
[root@server100 ~]# vim  /etc/nginx/conf.d/vhosts.conf
server {
        listen 80;
        server_name login.timinglee.org;
        rewrite ^/(.*)$  https://login.timinglee.org/$1 permanent;
}
测试
[root@server100 ~]# nginx -t
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful

[root@server100 ~]# systemctl restart nginx.service
[root@server100 ~]# curl  -I login.timinglee.org
HTTP/1.1 302  Moved Temporarily
Server: nginx/1.20.1
Date: Sat, 27 Apr 2024 10:23:39 GMT
Content-Type: text/html
Content-Length: 145
Connection: keep-alive
Location: https://login.timinglee.org

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值