[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