用proxy_pass替换路由

时间:2018-01-05 17:50:38

标签: nginx proxy routing

我有以下nginx文件可以使用,我有两个网址/us/api/us/castle。我想用{/ 1>替换/us/castle/knights

http://localhost:9000/us/castle/knights

error_log /Users/treggi/Projects/castle/nginx/error.log;
pid /Users/treggi/Projects/castle/nginx/nginx.pid;
worker_processes  1;
daemon off;
events { worker_connections  1024; }
http {
    access_log /Users/treggi/Projects/castle/nginx/access.log;
    include mime.types;
    default_type application/octet-stream;
    sendfile on;
    keepalive_timeout 65;
    server {
        listen 443 ssl;
        server_name localhost;
        ssl_certificate /Users/treggi/Projects/castle/nginx/nginx-selfsigned.crt;
        ssl_certificate_key /Users/treggi/Projects/castle/nginx/nginx-selfsigned.key;
        root /Users/treggi/Projects/castle/packages/castle-frontend/dist/site;
        location /us/api {
            proxy_pass http://localhost:3000;
        }
        location /us/castle {
            alias /Users/treggi/Projects/castle/packages/castle-frontend/dist/site;
            index index.dev.htm;
            try_files $uri $uri/ /index.dev.htm =404;
            autoindex on;
            expires 0;
        }
        autoindex on;
    }
}

我尝试添加这个新的location

location /us/castle/knights {
    proxy_pass http://localhost:9000/us/castle/knights
}

但它并没有取代这条特定的路线。

所以我拥有的就是这个,它不起作用:

error_log /Users/treggi/Projects/castle/nginx/error.log;
pid /Users/treggi/Projects/castle/nginx/nginx.pid;
worker_processes  1;
daemon off;
events { worker_connections  1024; }
http {
    access_log /Users/treggi/Projects/castle/nginx/access.log;
    include mime.types;
    default_type application/octet-stream;
    sendfile on;
    keepalive_timeout 65;
    server {
        listen 443 ssl;
        server_name localhost;
        ssl_certificate /Users/treggi/Projects/castle/nginx/nginx-selfsigned.crt;
        ssl_certificate_key /Users/treggi/Projects/castle/nginx/nginx-selfsigned.key;
        root /Users/treggi/Projects/castle/packages/castle-frontend/dist/site;
        location /us/api {
            proxy_pass http://localhost:3000/;
        }
        location /us/castle/knights {
            proxy_pass http://localhost:9000/us/castle/knights/;
        }
        location /us/castle {
            alias /Users/treggi/Projects/castle/packages/castle-frontend/dist/site;
            index index.dev.htm;
            try_files $uri $uri/ /index.dev.htm =404;
            autoindex on;
            expires 0;
        }
        autoindex on;
    }
}

0 个答案:

没有答案