Nginx's Web site building function

Nginx's Web site building function

foreword

I believe that many friends, like me when I first started learning, have little knowledge of Nginx. They know that it is a lightweight web server and reverse proxy server, and they can also tell some of its advantages and disadvantages, and they can also install and deploy it by themselves. But how to use it is still at a loss. Here I will briefly introduce the function of Nginx as a web server.

Preparation

If you don’t have Nginx installed, you can read my previous blog post

Deploy nginx under Centos7

If you can access the browser, the installation is successful

image-20230809134336665

Principle Description

An easy-to-understand explanation of how Nginx implements Web browser

You can view the default web page source code of Nginx

image-20230809134740627

These are the webpage files that come with Nginx installation, so can we replace them with webpage files written by ourselves, and the webpage files that we have written by ourselves will be accessed by the browser after entering the IP address? If it is changed to a public network IP, can everyone still access it? If we apply for a domain name through the public network IP, will it be the website we usually visit?

The answer is yes, of course, a website that can be launched is far more than that simple, but these are the foundations that can be realized

Modify webpage files

Enter the webpage file location after Nginx installation

This is the built-in web configuration file

[root@k8s-node-2 ~]# cd /usr/share/nginx/html/
[root@k8s-node-2 html]# ls
50x.html  index.html
[root@k8s-node-2 html]# cat index.html
<!DOCTYPE html>
<html>
<head>
<title>Welcome to nginx!</title>
<style>
html {
    
     color-scheme: light dark; }
body {
    
     width: 35em; margin: 0 auto;
font-family: Tahoma, Verdana, Arial, sans-serif; }
</style>
</head>
<body>
<h1>Welcome to nginx!</h1>
<p>If you see this page, the nginx web server is successfully installed and
working. Further configuration is required.</p>

<p>For online documentation and support please refer to
<a href="http://nginx.org/">nginx.org</a>.<br/>
Commercial support is available at
<a href="http://nginx.com/">nginx.com</a>.</p>

<p><em>Thank you for using nginx.</em></p>
</body>
</html>

Delete or rename the built-in webpage file

[root@k8s-node-2 html]# mv index.html 1
[root@k8s-node-2 html]# ls
1  50x.html

At this time, re-visit the browser, you can see that the previous welcome page is gone, and a 403 error is reported.

Prepare the webpage file you wrote, name it index.html and upload it to this directory

This is just a demonstration, I just found a web page file

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" lang="en">
	<head>
		<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
		<link rel="stylesheet" href="css/new_file.css" />
		<title>人民铁军-铁军由来</title>
	</head>
	<body>

<div id="page">
	<ul id="pictures">
		<li><img src="img/dunpai.jpg" </li>
		<li><img src="img/yeting.jpg" </li>
		<li><img src="img/heying.jpg" </li>
		<li class="last"><img src="img/dazhang.jpg" </li>
		</ul>
	<h1><span>人民铁军</span></h1>
	<h2>朱德</h2>
	<div id="intro">
		<ul>
			<li>[<a href="index.html">网站首页</a>]</li>
			<li>[<a href="origin.html">铁军由来</a>]</li>
			<li>[<a href="history.html">战斗历程</a>]</li>
			<li>[<a href="general.html">铁军将帅</a>]</li>
			<li>[<a href="tenfirst.html">十个第一</a>]</li>
			<li>[<a href="spirit.html">铁军精神</a>]</li>
		</ul>
		<p>
			铁军是指中部战区127旅,是一支历史悠久、战功卓著的英雄部队,是中国共产党掌握的
			第一支武装力量,素有“铁军”之称。
		<p>
			听党指挥,忠于人民,坚贞不渝的铁的信念;不怕牺牲,敢于胜利,百折不挠的铁的意志;军民一致,牢不可破的铁的团结;
			令行禁止,知己严明,秋毫无犯的铁的纪律;勇猛顽强,英勇善战,所向无敌的作风。
		</p>
	</div>
</div>
	</body>
</html>

Then upload the file you wrote to the server or virtual machine

Notice: Under the premise of not modifying the Nginx configuration file, it must be uploaded to the default directory:/usr/share/nginx/html

[root@k8s-node-2 html]# pwd
/usr/share/nginx/html
[root@k8s-node-2 html]# ls
1  50x.html  index.html
[root@k8s-node-2 html]# cat index.html
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" lang="en">
        <head>
                <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
                <link rel="stylesheet" href="css/new_file.css" />
                <title>人民铁军-铁军由来</title>
        </head>
        <body>

<div id="page">
        <ul id="pictures">
                <li><img src="img/dunpai.jpg" </li>
                <li><img src="img/yeting.jpg" </li>
                <li><img src="img/heying.jpg" </li>
                <li class="last"><img src="img/dazhang.jpg" </li>
                </ul>
        <h1><span>人民铁军</span></h1>
        <h2>朱德</h2>
        <div id="intro">
                <ul>
                        <li>[<a href="index.html">网站首页</a>]</li>
                        <li>[<a href="origin.html">铁军由来</a>]</li>
                        <li>[<a href="history.html">战斗历程</a>]</li>
                        <li>[<a href="general.html">铁军将帅</a>]</li>
                        <li>[<a href="tenfirst.html">十个第一</a>]</li>
                        <li>[<a href="spirit.html">铁军精神</a>]</li>
                </ul>
                <p>
                        铁军是指中部战区127旅,是一支历史悠久、战功卓著的英雄部队,是中国共产党掌握的
                        第一支武装力量,素有“铁军”之称。
                <p>
                        听党指挥,忠于人民,坚贞不渝的铁的信念;不怕牺牲,敢于胜利,百折不挠的铁的意志;军民一致,牢不可破的铁的团结;
                        令行禁止,知己严明,秋毫无犯的铁的纪律;勇猛顽强,英勇善战,所向无敌的作风。
                </p>
        </div>
</div>
        </body>
</html>

browser access

image-20230809141426425

At this time, through the browser access, you can see that it is the webpage file I prepared

Since I did not upload the picture, the picture cannot be loaded. I demonstrated it in a virtual machine, so only I can access it locally

If you want others to see it, you need a public network IP, because the internal network IP can only be accessed in the LAN

Configuration file description

Under normal circumstances, the browser enters the IP address, and the default access is port 80. If you do not want to enter the IP address and jump to your web page, you can modify the default port number of Nginx

If you don't want to modify the original welcome page that comes with Nginx, you can also modify the default access location of Nginx in the configuration file

Enter the configuration file of Nginx

The configuration files of different versions of Nginx may be in different places

Let's take the Nginx1.24 I installed as an example

[root@k8s-node-2 ~]# cd /etc/nginx/
[root@k8s-node-2 nginx]# ls
conf.d  fastcgi_params  mime.types  modules  nginx.conf  scgi_params  uwsgi_params
[root@k8s-node-2 nginx]# cd conf.d/
[root@k8s-node-2 conf.d]# ls
default.conf
[root@k8s-node-2 conf.d]# vim default.conf

image-20230809142410124

== Note : == If you want to modify the configuration file of Nginx, you need to reload the configuration file after modification to take effect

Reload command:nginx -s reload

Guess you like

Origin blog.csdn.net/huz1Vn/article/details/132187540