如何重写 URL 以匹配使用 nginx 的服务器?
How to rewrite URL to match a server using nginx?
我是 nginx 新手。我有两个项目,一个是django web app 运行 localhost 8000,另一个是tornado 用来提供api服务和运行 localhost 8888.
如何配置将所有 url 请求(从 80 端口)重定向到 localhost:8000 但 /api 请求 localhost:8888(tornado app)?
编辑您的 nginx
配置文件。添加一个 server
块并在 location
块中使用 proxy_pass
来代理(重定向)请求。
server {
listen 80;
location / {
proxy_pass http://127.0.0.1:8000;
}
location /api {
proxy_pass http://127.0.0.1:8888;
}
}
保存,重新加载nginx。
nginx -s reload
我是 nginx 新手。我有两个项目,一个是django web app 运行 localhost 8000,另一个是tornado 用来提供api服务和运行 localhost 8888.
如何配置将所有 url 请求(从 80 端口)重定向到 localhost:8000 但 /api 请求 localhost:8888(tornado app)?
编辑您的 nginx
配置文件。添加一个 server
块并在 location
块中使用 proxy_pass
来代理(重定向)请求。
server {
listen 80;
location / {
proxy_pass http://127.0.0.1:8000;
}
location /api {
proxy_pass http://127.0.0.1:8888;
}
}
保存,重新加载nginx。
nginx -s reload