I figured out nginx configure!

As we all known, our dear droplet website is built with Nginx. Nginx is a web serverthat I like more than Apache.To explain it to you briefly, let me first talk about the structure of a website.

As we all know, a website is about like this:

First, there is a host. You want to store all the files on this host, right? The website, of course, also exists in a directory of this host. You also have a computer, and of course you can use your machine to do it. Your machine may be windows system, it may be macOS, but my host is using Linux system, and it is a virtual machine. Most of the website builders are also using virtual machines with Linux operating systems.

Second, your website needs to have a database. In this way, you can install all the data of your website in the most concise, efficient and orderly way, and it is easy to find and change. Our website may sometimes move, relocate, reinstall, or change shells. At this time, just back up and migrate the database. Is it much more efficient? The database software I use is called mysql.

Again, it's the web server. A web server provides various web communication services. From a browser on another machine, the visitor enters:http://somedomain.com, is to use the http service to access the folder containing the "website" in the machine pointed to by the domain name. When you visited, why did the machine respond to you? It is because its web server program has been listening on a certain port, so once the port is accessed externally, it returns you to the place where it should be returned. Nginx is a web server that provides you with http services and https services.

Finally, it is a scripting language that translates the source code into a web page that is displayed in front of your eyes. We are using the PHP scripting language.

In addition, a website also needs to register a domain name and resolve the domain name to the ip of the host where the "website" is installed. You don't directly enter the host's ip in the browser, right, you enter the domain name to access. But because the domain name is successfully resolved to the host's ip, you can access the website on this host through the domain name.

In addition, most of the rookies like me don't write php/html directly. So we'll use sometruly humane`platforms with graphical interfaces to manage websites. For example, I use wordpress. In this way, when I write a blog, I can just click with the mouse and type, so I don't need to write the source code of the website.

The above is roughly how a website is set up.

nginx is a web server software.

Nginx can provide http services or https services. But to enable https service, ssl certificate is required. Because they are two different services, we write them in different server modules and listen on different ports (http generally uses port 80, https uses port 443):



The first and third are both http services, listening on port 80. What is the difference between the two? Let's see, the first server`name end up with_, that is to access through the local ip, then the root directory is /usr/local/nginx/html, and the index is index.html, index.htm or index.php, that is to say, you access through the local ip, the http service gives You have sent the index, index.htm or index.php files in the '/usr/local/nginx/html' directory of my virtual machine.

The interface looks like this:

And the third, server_name is fangmuseum.com, www.fangmuseum.com and *.fangmuseum.com, the root directory is /home/wwwroot/fangmuseum.com, the index is index.html, index.htm and so on. That is to say, when you visit the domain name "fangmuseum.com" of our droplet website, the http service will send you to index.html or index in the "/home/wwwroot/fangmuseum.com" directory of my virtual machine. .htm or index.php. This directory is the root directory of our droplet website. I use the php scripting language, the index.php file can be found in this directory, so it will send you to index.php.

The second is to open the https service, which is listening on port 443. Because it is an https service, it depends on your ssl certificate, so there are two lines of "ssl_certificate" in the middle.

Write here for now. If you have any questions, just message me.

Posts created 66

3 thoughts on “我学会了nginx配置

  1. Can I simply say what a comfort to discover someone who genuinely understands what they are talking about online. You definitely realize how to bring a problem to light and make it important. More people need to read this and understand this side of your story. I cant believe you arent more popular because you definitely possess the gift.

    1. Thank you so much for your encouragement! I’m happy to hear that you find it useful! Frankly speaking, It’s hard to get more visitors to most personal blogs like mine nowadays. But I’ll keep writing and posting good quality articles for people like you.

Leave a Reply

Your email address will not be published. Required fields are marked *

Related Posts

Begin typing your search term above and press enter to search. Press ESC to cancel.

Back To Top