有趣的问题我有这个python代码:
import sys, bottle, gevent
from bottle import *
from gevent import *
from gevent.wsgi import WSGIServer
@route("/")
def index():
yield "/"
application=bottle.default_app()
WSGIServer(('', port), application, spawn=None).serve_forever()
它独立运行,nignx 位于其前面作为反向代理。
现在,这些代码片段分别运行,但我在每个域的每个项目(目录)中运行多个代码片段,但代码出于某种原因认为它是顶级的,但事实并非如此,当您访问 mydomain.com/something 时它可以工作,但如果您访问 mydomain.com/something/ 您将收到错误。不,我已经测试并发现 nginx 正在从请求/查询中删除“something”,因此当您访问 mydomain.com/something/ 时,代码认为您要访问 mydomain.com// 我如何让 nginx 停止删除此信息?
Nginx 站点代码:
upstream mydomain {
server 127.0.0.1:10100 max_fails=5 fail_timeout=10s;
}
upstream subdirectory {
server 127.0.0.1:10199 max_fails=5 fail_timeout=10s;
}
server {
listen 80;
server_name mydomain.com;
access_log /var/log/nginx/access.log;
location /sub {
proxy_pass http://subdirectory/;
proxy_redirect off;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_max_temp_file_size 0;
client_max_body_size 10m;
client_body_buffer_size 128k;
proxy_connect_timeout 90;
proxy_send_timeout 90;
proxy_read_timeout 90;
proxy_buffer_size 4k;
proxy_buffers 4 32k;
proxy_busy_buffers_size 64k;
proxy_temp_file_write_size 64k;
}
location /subdir {
proxy_pass http://subdirectory/;
proxy_redirect off;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_max_temp_file_size 0;
client_max_body_size 10m;
client_body_buffer_size 128k;
proxy_connect_timeout 90;
proxy_send_timeout 90;
proxy_read_timeout 90;
proxy_buffer_size 4k;
proxy_buffers 4 32k;
proxy_busy_buffers_size 64k;
proxy_temp_file_write_size 64k;
}
}
答案1
我想到了 :]
显然,在 proxy_pass 中你需要告诉它子目录,就像请求一样:
location /sub {
proxy_pass http://subdirectory/sub; // here the location ie: /sub needs to be passed to the underlieing
proxy_redirect off;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_max_temp_file_size 0;
client_max_body_size 10m;
client_body_buffer_size 128k;
proxy_connect_timeout 90;
proxy_send_timeout 90;
proxy_read_timeout 90;
proxy_buffer_size 4k;
proxy_buffers 4 32k;
proxy_busy_buffers_size 64k;
proxy_temp_file_write_size 64k;
}