Comments (3)
其实在实践的过程中实践浪费的最多还是在搭建环境上,或者说是实验拓扑吧。
最开始的想法是利用docker
的,结果没玩转过来,最后无奈只好在本地利用nginx勉强弄了。
server {
listen 80;
server_name demo.com;
# proxy
location / {
proxy_pass http://127.0.0.1:8082/;
}
access_log /usr/local/etc/nginx/logs/demo.access.log;
}
server {
listen 80;
server_name api.demo.com;
# proxy
location / {
proxy_pass http://127.0.0.1:9000/;
}
access_log /usr/local/etc/nginx/logs/api.demo.access.log;
}
server {
listen 80;
server_name data.demo.com;
# proxy
location / {
proxy_pass http://127.0.0.1:9000/demo/;
}
access_log /usr/local/etc/nginx/logs/data.demo.access.log;
}
server {
listen 80;
server_name static.demo.com;
# proxy
location / {
proxy_pass http://127.0.0.1:8083;
}
access_log /usr/local/etc/nginx/logs/static.demo.access.log;
}
server {
listen 80;
server_name stream.demo.com;
# proxy
location / {
proxy_pass http://127.0.0.1:8084;
}
access_log /usr/local/etc/nginx/logs/stream.demo.access.log;
}
from genffy.
location 与 proxy_pass 搭配使用几种情况
最近做迁移遇到了一些 location
与 proxy_pass
搭配使用遇到的几种情况在这里总结下:
location | proxy_pass | Request | Received by upstream |
---|---|---|---|
/webapp/ | http://localhost:5000/api/ | /webapp/foo?bar=baz | /api/foo?bar=baz |
/webapp/ | http://localhost:5000/api | /webapp/foo?bar=baz | /apifoo?bar=baz |
/webapp | http://localhost:5000/api/ | /webapp/foo?bar=baz | /api//foo?bar=baz |
/webapp | http://localhost:5000/api | /webapp/foo?bar=baz | /api/foo?bar=baz |
/webapp | http://localhost:5000/api | /webappfoo?bar=baz | /apifoo?bar=baz |
/webapp | http://localhost:5000 | /webapp/foo?bar=baz | /webapp/foo?bar=baz |
/webapp | http://localhost:5000/ | /webapp/foo?bar=baz | /foo?bar=baz |
参考:https://dev.to/danielkun/nginx-everything-about-proxypass-2ona
from genffy.
nginx 修改 cookie key 的方案
刚好最近遇到一个需要转换 cookie key 的场景,打通两个网关,网上找了个感觉还挺有用的,然后贴一下实际使用的完整配置。
原答案:remove-specific-cookie-in-nginx-reverse-proxy.
location /api {
# save original "Cookie" header value
set $altered_cookie $http_cookie;
# check if the "my_cookie" cookie is present
if ($http_cookie ~ '(.*)(^|;\s)my_cookie=("[^"]*"|[^\s]*[^;]?)(\2|$|;$)(?:;\s)?(.*)') {
# cut "my_cookie" cookie from the string
set $altered_cookie "$1$4$5;your_define_key=$cookie_my_cookie";
}
# hide original "Cookie" header
proxy_hide_header Cookie;
# set "Cookie" header to the new value
proxy_set_header Cookie $altered_cookie;
... # other proxy settings here
proxy_pass <upstream>; # change to your upstream server
}
from genffy.
Related Issues (10)
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from genffy.