Nginx User Guide: Installation, Configuration, and Basic Usage

insert image description here

foreword

This user guide will help you understand how to install, configure and basically use Nginx. Nginx is a high-performance open source web server and reverse proxy server with powerful performance and flexibility to meet various web server needs.

Install Nginx

a. Install on Ubuntu:

$ sudo apt update
$ sudo apt install nginx

b. Install on CentOS:

$ sudo yum install nginx

c. Install on Windows

Open the Nginx official website (https://nginx.org), go to the download page, find the Windows version of Nginx, and download the corresponding version of the Windows installation package (eg nginx-1.20.1.zip).
Just unzip the compressed package.

Configure Nginx

a. Main configuration file location:

The main configuration file for Nginx is /etc/nginx/nginx.conf. This file can be opened with a text editor for configuration.

b. Modify the listening port:

By default, Nginx listens on port 80 as an HTTP service. You can find the listen section in the configuration file, and modify the port number to your desired port.

c. Configure the virtual host:

Web hosting allows you to host multiple websites on the same server. Virtual hosts can be created by configuring multiple server blocks in the configuration file. Each server block contains an independent domain name and related configuration information.

Start and stop Nginx

a. Start the Nginx service:

$ sudo nginx

b. Stop the Nginx service:

$ sudo nginx -s stop

basic use

a. Static file server:

Serving static files with Nginx is very simple. Place your static files in the directory specified in the Nginx configuration file, and then access them directly through the browser.

b. Reverse proxy server:

Nginx can also act as a reverse proxy server, forwarding requests to backend servers for processing. By configuring reverse proxy, functions such as load balancing and high availability can be realized.

Common commands

a. Check whether the syntax of the configuration file is correct:

$ sudo nginx -t

b. Reload the configuration file:

$ sudo nginx -s reload

c. View the running status of Nginx:

$ sudo systemctl status nginx

Summarize

The above is a basic Nginx user guide, which introduces installation, configuration and basic usage. You can learn more about Nginx's advanced features and more complex configuration options according to actual needs. For more detailed content and further guidance, please refer to the official Nginx documentation. Good luck with Nginx!

Guess you like

Origin blog.csdn.net/m290345792/article/details/131856716