Task duration: 15 to 30 minutes

Build a static website, the first need to deploy the environment. The following steps will show you how to deploy HTTP static services on a server using Nginx.

Install Nginx

On CentOS, you can install Nginx directly with yum

yum install nginx -y
Copy the code

After the installation is complete, start nginx using the nginx command:

nginx
Copy the code

At this point, visit http://< your domain name > to see the Nginx test page [?]

If not, retry the nginx -s reload command to restart nginx

Configure the static server access path

The Web service for extranet users to access the server is provided by Nginx. Nginx needs to configure the path information of static resources to correctly access static resources on the server through urls.

Open the default configuration file for Nginx

/etc/nginx/nginx.conf

root /usr/share/nginx/html;
root /data/www;

server { listen 80 default_server; listen [::]:80 default_server; server_name www.qq.com; // Your domain name root /data/ WWW; Include /etc/nginx/default.d/*.conf; location / { } error_page 404 /404.html; location = /40x.html { } error_page 500 502 503 504 /50x.html; location = /50x.html { } } }Copy the code

The configuration file takes /data/ WWW/as the root path for all static resource requests, such as visiting: http://< your domain name >/index.html, will go

/data/www/

Go to the directory and look for index.html. Now we need to restart Nginx for the new configuration to take effect, such as:

nginx -s reload
Copy the code

After the restart, we should now be able to use our static server. Let’s now create a new static file to see if the service is working properly.

First let’s create a WWW directory under /data as follows:

mkdir -p /data/www
Copy the code

Create your first static file

Create our first static file index. HTML under /data/ WWW

Now visit http://< your domain name >/index.html and you should see the page output [Hello World!

At this point, a static server based on Nginx is set up, and now all static resources in the /data/ WWW directory can be directly accessed by domain name.

If no, refresh the browser page

Complete!!!!!