Beginner's Guide to Nginx: From Installation to Reverse Proxy Configuration
Nginx is a high-performance HTTP and reverse proxy server, lightweight and stable, suitable for scenarios such as website building and load balancing. Installation is divided into Ubuntu/Debian (`sudo apt install nginx`) and CentOS/RHEL (`sudo yum install nginx`). Verification is done with `nginx -v`. Start the service (`sudo systemctl start nginx`) and set it to start automatically (`sudo systemctl enable nginx`). Management commands include start/stop, restart, and reload configuration (`reload`). For core reverse proxy configuration: Create a site configuration file (e.g., `myapp.conf`) in `/etc/nginx/conf.d/`. Example configuration: The `server` listens on port 80, `server_name` is set to the domain name/IP, `location /` forwards to the backend port (e.g., `127.0.0.1:3000`) via `proxy_pass`, and passes Host and real IP through `proxy_set_header`. After configuration, check syntax with `nginx -t`, and `reload` to apply changes, then test access to the backend content. Notes: Open ports 80/443 in the firewall, ensure the backend service is running, and `proxy_pass` must start with `http://`/`https://`.
Read More