Skip to content

Instantly share code, notes, and snippets.

@swateek
Forked from anjia0532/nginx.conf
Created July 6, 2018 08:00
Show Gist options
  • Save swateek/725ea1e25c225d9fffe21ada52b04dfb to your computer and use it in GitHub Desktop.
Save swateek/725ea1e25c225d9fffe21ada52b04dfb to your computer and use it in GitHub Desktop.
nginx proxy_pass add a static parameter
worker_processes 1;
events {
worker_connections 1024;
}
http {
include mime.types;
default_type application/octet-stream;
log_format main '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"';
access_log logs/access.log main;
sendfile on;
keepalive_timeout 65;
server {
listen 47777;
server_name localhost;
access_log logs/47777.access.log main;
set $token ""; # declar token is ""(empty str) for original request without args,because $is_args concat any var will be `?`
if ($is_args) { # if the request has args update token to "&"
set $token "&";
}
location /test {
set $args "${args}${token}k1=v1&k2=v2"; # update original append custom params with $token
# if no args $is_args is empty str,else it's "?"
# http is scheme
# service is upstream server
proxy_pass http://127.0.0.1:46666$uri$is_args$args; # proxy pass
}
}
server {
listen 46666;
server_name localhost;
access_log logs/46666.access.log main;
location / {
root html;
index index.html index.htm;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment