Creating NGINX Rewrite Rules

Creating NGINX Rewrite Rules

https://www.nginx.com/blog/creating-nginx-rewrite-rules/

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

server {
    listen 80;
    listen 443 ssl;
    server_name www.old-name.com;
    return 301 $scheme://www.new-name.com$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‑name.com. 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.

发表评论

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