I have set up a POP3 reverse proxy and is being used to serve multiple domains. I was thinking to pass the hostname of the request to the auth script as a custom header, but I don't know how.
The relevant section of the nginx.conf file is:
mail {
server_name mail.example.com;
auth_http 10.169.15.199:80/auth_script.php;
auth_http_timeout 5000;
proxy on;
proxy_pass_error_message on;
pop3_capabilities "LAST" "TOP" "USER" "PIPELINING" "UIDL";
server {
protocol pop3;
listen 110;
pop3_auth plain;
auth_http_header X-Auth-Port 110;
auth_http_header User-Agent "Nginx POP3/IMAP4 proxy";
auth_http_header my_hostname $host;
}
}
I tried with this:
auth_http_header my_hostname $host;
expecting nginx to replace the $host with the actual hostname, but it does not happen, the auth script receives $_SERVER[MY_HOSTNAME] = '$host'.
Is there any way I can accomplish this?
The only way to get the host of the auth, is authenticating like user#hostname.tld and in the auth headers split the part of the hostname.
If you want to proxy auth to multiple domains I wrote a module in perl
Related
I plan to run an pgAdmin4 instance behind Nginx reverse proxy.
What I want is requests coming to http://myhost.com/pgadmin4 should be forwarded to upstream http://localhost:8087 where pgAdmin is listening.
To achieve this, I followed this nginx.conf recipe from pgAdmin's official doc. Here's the snippet:
server {
listen 80;
server_name myhost.com;
location /pgadmin4/ {
proxy_set_header X-Script-Name /pgadmin4;
proxy_set_header Host $host;
proxy_pass http://localhost:8087/;
proxy_redirect off;
}
}
Everything works fine except that after successful login, the server sends HTTP 301 response with location header sets to root path (i.e. "Location: /") aand bam, user agent is redirected to http://myhost.com/ where nothing is waiting (except nginx default page, for now).
Retyping the url to http://myhost.com/pgadmin4/ is still okay. The user agent's state, cookies and all are all set and user can continue as normal. It's just that it's a mild annoyance for end users having to retype the whole URL again.
I know that I can alter upstream's HTTP redirect response by using proxy_redirect directive, but I can't figure out what the value should be.
Is what I'm trying to do achievable from just by Nginx configuration? Is there any specific PgAdmin4 config that I need to change?
I'm using nginx for web service proxy. I have rest service as below and i want to proxy my domain
https://www.example.com/myRestservice. Service has some method like this;
http://1.1.1.1:123/api/work/method1
http://1.1.1.1:123/api/work/method2
*By the way services publish on two server as below in nginx.conf
As result i want to access to methods of service like "https://www.example.com/Restservice/api/work/method1"..
When i try to use rewrite in nginx as below, i can access service.
But in this time Post method's request body is emty. I can see service logs.
In my nginx.config
upstream RestService {
server 1.1.1.1:123;
server 1.1.1.2:123;
}
server {
listen 443 ssl;
server name https://www.example.com;
location ~ ^/Restservice/ {
add_header Access-Control-Allow-Origin *;
rewrite ^/Restservice/(.*) /$1 break;
proxy_pass http://Restservice/;
proxy_http_version 1.1;
}
}
Bye the way i try to location part like this, result is same.
location /Restservice {
proxy_pass http://Restservice/;
}
Normally I can access soap service with config from https link.
Is it about http redirection to https ?
In nginx access log;
status : 500
request: POST /Restservice/api/work/method1 HTTP/1.1
I find the reason. Because of the endcoding.
After choosing endcoding type 'UTF-8', I could see request body.
I am trying to use nginx as a reverse proxy, but I couldn't find anything on how to forward the x-access-token (JWT) header.
The reverse proxy works fine, and using http://localhost/app gives me the api. However, when I try to access anything requiring a token, ex. http://localhost/app/api/products I get Cannot GET //api/products.
In the documentation, it says that the default is proxy_pass_request_headers on; but the problem doesn't seem to be there.
nginx.conf
events {}
http {
server {
listen 8000;
location /app {
proxy_pass 'http://localhost:3000/';
}
}
}
I have alfresco installed on a server, I want to force alfresco to only serve 1 language (italian) so, since it normally reads the language wanted from the http header, i set up an nginx reverse proxy to change the header.
The proxy runs on the server and listens to connections on port 80 and redirects them to the port 8080 where the alfresc otomcat server is running.
This is my server code in the nginx conf file:
server {
set $language 'it-IT';
add_header Accept-Language $language;
listen 80;
server_name alfresco
access_log logs/host.access.log main;
location / {
root html;
proxy_pass http://<serverip>:8080;
proxy_set_header Accept-Language $language;
proxy_set_header Host $host;
}
}
Everything works nicely, now i wanted to substitue with localhost (or 127.0.0.1), i thought that it should work since nginx is running on the same server as alfresco but it doesn't.
In particular, when i use and type the ip in the address bad of another machine i will get redirected correctly to http:///share/page/ and the page will be in italian (as expected)
but when i try to put localhost or 127.0.0.1 i will get redirected to http://:8080/share/page/ and the page will have the language i have in my browser.
Does anyone have an idea as to why this happens?
I'm configuring an application that will authenticate a user, and then set the X-Accel-Redirect header and a private api key, Foo (for testing purposes), that will be passed on to the proxied endpoint.
I'm setting the private api key as a header in the authenticating application, and have the following location block in my nginx configuration file. How do I set the header to the proxied application based on what the upsteam server sets? I've also tried using $http_foo and $sent_http_foo. Currently, the Foo response header is never set for the proxy.
location ~* ^/redirect {
internal;
resolver 8.8.8.8;
proxy_ssl_server_name on;
add_header Foo $upstream_http_foo;
set $my_host "requestb.in";
set $my_uri "a_test_uri";
proxy_pass http://$my_host/$my_uri;
}
The directive to use is proxy_set_header, so in your case:
proxy_set_header Foo $http_api_key; # assuming a "API-Key" header incoming
As a general rule, any settings you intend to apply to your communication with an upstream will be prefixed with proxy_