Centos
具有單獨別名的 Nginx 反向代理
有趣的問題我有這個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 正在從請求/查詢中刪除“某物”,因此當您訪問 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; } }
我想到了 :]
顯然在 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; }