Alibaba Cloud Nginx Ultimate Tutorial: From Static Website Deployment to High Performance Reverse Proxy Configuration

cloud 2026-07-08 阅读 40
1

In today's digital transformation of enterprises, building a highly available, highly concurrent and elegant Web system is inseparable from reasonable cloud infrastructure and excellent Web server selection. As the top computing power base in China and even in the world, Alibaba Cloud's cloud server ECS(Elastic Compute Service) is matched with a high-performance asynchronous event-driven server.

Nginx

, has become the standard of most Internet architectures.

Whether it is an enterprise going out to sea, cross-border e-commerce, or local high concurrent applications, sorting out the core configuration of Nginx is a required course for system architects and operation and maintenance engineers. This article will be based on the actual combat, from

Environment construction, static website deployment, reverse proxy and dynamic and static separation configuration

Such as dimensions, take you in-depth grasp of the Alibaba Cloud environment Nginx advanced tuning.

Preparatory work: infrastructure preparation

Before you can start configuring everything, you first need to have a Linux server running in the cloud.

📌Architecture selection tips: for overseas enterprises or businesses that have rigid requirements for exemption from filing, Alibaba Cloud International Edition (such as Hong Kong, Singapore, and US-West nodes) is usually selected. For businesses that deeply cultivate the domestic market, the mainland node is more inclined to the domestic version. Many offshore enterprises are unable to register directly due to lack of overseas payment methods or overseas identity information. At this time, Alibaba Cloud account purchase and compliance recharge through officially authorized channel providers have become the most efficient and secure selection scheme in the industry.

1. Open security group ports

When your ECS instance is ready, you first need to log on to the Aliyun console, add direction rules to the corresponding security group (Security group) of the instance, and release the following two core Web ports:

TCP port 80: Used for regular HTTP access.

TCP 443 port: Used for encrypted HTTPS access.

2. System environment update and Nginx installation

With the current mainstream

Alinux 3 / CentOS 8

system as an example, we use

dnf

or

yum

Package Manager Quick Install Nginx:

Bash

# Update the system software package

sudo dnf update -y

Install Nginx

sudo dnf install -y nginx

# Start the service and set the boot

sudo systemctl start nginx

sudo systemctl enable nginx

# Check the running status of Nginx

sudo systemctl status nginx

When the status is displayed

active (running)

Enter the public IP of your ECS in the browser. If you see

Nginx's welcome page indicates that the underlying environment has been successfully built.

1. Advanced Combat: Highly Cohesive Static Website Deployment

In actual production, directly modify the main configuration file

/etc/nginx/nginx.conf

Not a good habit. The best practice for Nginx is

Keep the main configuration file clean and create a separate. conf configuration file in the/etc/nginx/conf.d/directory for each independent website

.

Suppose we want to deploy a front-end modern single-page application (SPA, such as Vue or React project).

1. Standardize the creation of a project directory.

Bash

sudo mkdir -p /www/wwwroot/mysite

# upload the files in the dist directory packaged by the front end to this directory

2. Write a site configuration file

In

/etc/nginx/conf.d/

Create under directory

mysite.conf

:

Bash

sudo vim /etc/nginx/conf.d/mysite.conf

Fill in the following production environment standard configuration:

Nginx

server {

listen 80;

server_name www.example.com example.com;# Replace with your real domain name

root /www/wwwroot/mysite;

index index.html index.htm;

# Turn on Gzip compression to significantly improve the loading speed of the first screen in the sea network environment

gzip on;

1k gzip_min_length;

gzip_comp_level 6;

gzip_types text/plain text/css application/json application/javascript text/xml;

# Resolve the 404 problem in front-end routing history mode (History Mode)

location / {

try_files $uri $uri/ /index.html;

}

# Static resource cache optimization

location ~* \.(jpg|jpeg|png|gif|ico|css|js)$ {

expires 7d;

access_log off;

}

# Error page redirection

error_page 404/404. html;

error_page 500 502 503 504 /50x.html;

location = /50x.html {

root /usr/share/nginx/html;

}

}

⚠Compliance Reminder: If your domain name resolution points to an ECS instance in Aliyun mainland China, the domain name must complete ICP filing with the Ministry of Industry and Information Technology, otherwise Aliyun's border firewall will automatically block access requests from port 80/443. If the business cannot be filed, it is recommended to purchase the international website service through the Alibaba Cloud account through the channel provider and deploy the website in Hong Kong or overseas nodes.

2. Core Advanced: Reverse Proxy and Dynamic and Static Separation Configuration

Reverse Proxy (Reverse Proxy) is the most powerful feature of Nginx. In this architecture, Nginx acts as the only entry for traffic, receiving requests from clients and then forwarding them internally to the real application server at the back end (such as Tomcat, Node.js, Go, Python or Spring Boot).

This can not only

Hide the real IP address of the backend server

Increased security and higher concurrent throughput.

1. Base Reverse Proxy

Suppose your back-end Spring Boot application is running on the same instance.

8080

port, and do not want to expose 8080 port to the outside. We can configure this in Nginx:

2. Advanced production level: dynamic and static separation and multi-port routing

In more complex enterprise architectures, we tend to use the same domain name and distinguish it by URL prefix.

Front-end static resources

with

Backend dynamic API interface

:

through this

Static and Dynamic Separation

Nginx does not need to disturb the back-end Java/Go process when processing highly concurrent static requests of pictures, CSS and JS, which not only greatly reduces the memory overhead of the back-end server, but also doubles the throughput limit of the entire website system.

3. Configuration Validation and Operation & Maintenance Pit Avoidance Guide

After modifying the Nginx configuration file,

Do not restart the service directly and blindly.

. If there is a syntax error in the configuration (for example, a semicolon is missing

;

Or the curly braces are not closed), a direct restart will cause the online Web service to crash instantly and cannot be pulled up.

Correct smooth reloading process

1. Grammar verification: to ensure the safety of online services.

Execute in terminal

sudo nginx -t

Order.

If returning

nginx: configuration file ... test is successful

, prove that the syntax of the configuration file is completely positive.

Indeed.

2. Smooth heavy load (Reload): zero downtime hot update.

Executing command:

sudo systemctl reload nginx

.

reload

with

restart

Different, it will guide Nginx's Master process to smoothly derive a new Worker process to handle new requests, while the old Worker process will be automatically destroyed after processing the current connection, thus realizing

Completely Zero Business Interruption

Configuration updates.

4. Summary and Suggestions for Seaside Selection of Enterprises

The configuration of Nginx is ever-changing, but it remains the same. Through reasonable virtual host division, rigorous

proxy_pass

The request header is transmitted through, and with the stable and excellent network link of Aliyun ECS, you can easily support the application of millions of PV every day.

Finally, senior cloud computing practitioners remind you:

The architecture must be designed to serve compliance.

If you find that the back-end API delay is too high due to cross-border network fluctuations during the configuration process, or the market opportunity is missed due to the long filing cycle, you should make long-term plans at the early stage of planning. For enterprises with specific overseas business expansion claims, choose a formal, official contractual third-party Reseller channel.

Purchase with an Alibaba Cloud account

The international version of the service, avoiding complex real-name and regional access restrictions from the source, is the golden rule to ensure the smooth landing of overseas business.

2
← 返回新闻中心