This is the 23rd day of my participation in the August More Text Challenge.More challenges in August

preface

Nginx and Apache HTTP Server are popular Web Server software in the industry, but compared with Apache HTTP Server, Nginx is more lightweight and high-performance, so after understanding Apache HTTP Server, Today we are going to enter the world of Nginx.

practice

The installation

yum -y install nginx
Copy the code

HTTP

Visit http:// {server_ip}

From the response header we can see that the server type is: nginx/1.20.1

Modifying the Default Home Page

The default site path for nginx is /usr/share/nginx/html

We modify the contents of index.html in this path to:

<! DOCTYPEhtml>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="Width = device - width, initial - scale = 1.0">
    <title>Document</title>
    <script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/vue.js"></script>
<body>
    <div id="appv">Please enter:<br><br>
                <textarea rows="" cols="" v-model="info"></textarea>
        <! -- <input v-model="info"> -->
        <p style="white-space: pre-line;">What you type is:<br><br>{{ info }}</p>
    </div>
    <script>
        app = new Vue({
            el: "#appv".data: {
                info: "placeholder",}})</script>
</body>
</html>
Copy the code

Visit again to see the effect:

HTTPS

Nginx does not support HTTPS by default. The default nginx configuration path is /etc/nginx/nginx.conf

Try: https://{server_ip}

Modify the configuration

vim /etc/nginx/nginx.conf

The following configuration is commented out by default, so let go of the comment.

According to the above configuration, we copy from the visa to the specified path. For the method of generating certificates, see the previous article, which has been introduced.

Cp server. CRT /etc/pki/nginx/ cp server.key /etc/pki/nginx/private/Copy the code

HTTPS Access

Try again: https://{server_ip}

As we can see, HTTPS for Nginx is done. Click advanced to continue:

We made it to the home page.

Extension: implement URL jump

Goal: when visiting https:// {server_ip} / me, automatically jump to: https://phygerr.github.io.

Nginx configuration

Add the following configuration:

location /me{ rewrite .+ https://phygerr.github.io; } '> HTTP redirect is configured in the HTTP server section, and HTTPS redirect is configured in the HTTPS server section.Copy the code

After the configuration, run the systemctl restart nginx command to restart nginx.

Visit https://{server_ip}/me to see the results:

Thank you for reading, don’t forget to follow, like, comment, forward four consecutive yo!