Creating NGINX Rewrite Rules

Creating NGINX Rewrite Rules

Here’s a very simple example that redirects clients to a new domain name:

server {
    listen 80;
    listen 443 ssl;
    return 301 $scheme://$request_uri;

The listen directives mean the server block applies to both HTTP and HTTPS traffic. Theserver_name directive matches request URLs that have domain name www.old‑ Thereturn directive tells NGINX to stop processing the request and immediately send code301 (Moved Permanently) and the specified rewritten URL to the client. The rewritten URL uses twoNGINX variables to capture and replicate values from the original request URL: $scheme is the protocol (http or https) and $request_uri is the full URI including arguments.


电子邮件地址不会被公开。 必填项已用*标注