最简单的Nginx路由重写方法

Published: Tags: NGINX

TALK IS CHEAP, SHOW ME THE CODE(屁话少说,放码过来)

server {
    listen       80;
    listen       443 ssl;

    server_name  api.jtwo.me  sand-api.jtwo.me;

    ssl_certificate      "/data/certificate/nginx.crt";
    ssl_certificate_key  "/data/certificate/nginx.key";

    root /data/api;

    location / {
        rewrite  ^/(.*)$  /gateway.php?cmd=$1  break;

        include        fastcgi_params;
        fastcgi_pass   127.0.0.1:9001;
        fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
    }

    location = /favicon.ico {
        access_log off; log_not_found off;
    }
}