Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
785 views
in Technique[技术] by (71.8m points)

regex - Nginx - Rewrite the request_uri before uwsgi_pass

I have a Nginx vhost than is configured as such:

...
location /one {
  include uwsgi_params;
  uwsgi_pass unix:///.../one.sock;
}
location /two {
  include uwsgi_params;
  uwsgi_pass unix:///.../two.sock
}
...

This is a simplified configuration of course

When I request /one/something I would like my Python script to receive /something as request_uri.

I'm using BottlePy but would like this to be handled by Nginx and not in my Python code.

Can I do something like uwsgi_param REQUEST_URI replace($request_uri, '^/one', '')?

Edit

Here is the request from my Python code: [pid: 30052|app: 0|req: 1/1] () {42 vars in 844 bytes} [Tue Aug 21 14:22:07 2012] GET /one/something => generated 0 bytes in 4 msecs (HTTP/1.1 200) 2 headers in 85 bytes (0 switches on core 0)

So Python is OK but uWSGI is not.

How to fix that?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
location /one {
  rewrite /one/(.+) /$1 break;
  include uwsgi_params;
  uwsgi_pass unix:///.../one.sock;
}

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

2.1m questions

2.1m answers

60 comments

57.0k users

...