Nginx set_proxy_header host adds www to the host - nginx

location / {
proxy_set_header Host sub.domain.host.com;
proxy_pass https://other.host.com/;
}
The host header ends up being www.sub.domain.host.com, is there a way to prevent the www from being added?

Edit, I was wrong. You can create more levels on your domain.
https://webmasters.stackexchange.com/questions/77534/subdomain-of-subdomain-how-is-it-possible

Related

Issue accessing plotly dash behind nginx

I have a dash plotly running on a VM with ip address 192.168.8.3 on port 5050. Locally, I can access the dashboard using the url http://192.168.8.3:5050.
Now I am trying to enable access via Nginx on http://myserver.com/dashboard/devs. However, when i try access it, in the browser console there is some files not found:
GET http://myserver.com/assets/header.css?m=1597279663.0
GET http://myserver.com/assets/typography.css?m=1597279663.0
This is my nginx configuration:
server {
server_name myserver.com;
location /dashboard/devs {
rewrite ^/(dashboard/devs)/(.*) /$2 break;
proxy_pass http://192.168.8.3:5050;
proxy_set_header X-Real_IP $remote_addr
...
proxy_set_header Host $http_host;
proxy_redirect off;
}
}
Finally it was resolved using flask to redirect "/" requests to "/dashboard/devs/". The nginx configuration was left untouched.

nginx reverse proxy for kibana

I am using this part in nginx config file
location ~ ^/kibana(.*) {
rewrite /kibana/(.*) /$1 break;
proxy_pass http://core-services-local-nginx-ingress-controller.kube-system:80;
proxy_redirect off;
proxy_set_header Host "kibana-service-local";
}
but the issue is ,when i do localhost/kibana/ it is redirecting to localhost/app/kibana and displaying 4o4 not found .
why it is happening? how to resolve this issue?I want kibana dashboard to come when hitting localhost/kibana/.
set the server.basePath setting in kibana.yml to /kibana.

How to point Dns and manage Nginx redirection properly

I am facing the following situation:
I own a domain name, let's say example.com at name.com
We have a website hosted at bluehost on a shared hosting with an IP1
We have an ERP (odoo) hosted at digitalocean on a droplet where Nginx is running and where IP2 is allocated.
The erp is accesible via IP2:port_number
I am trying to redirect erp.example.com in direction of odoo while keeping the main domaine http://example.com to point to IP1
I have tried to setup two A record. One for erp.example.com to point to IP2 but here I can not specify the port at name.com, problem is it doesn't seems even to point on the 80 port as I don't see the Nginx welcome page when I type http://erp.example.com
I have setup another A record which point to the bluehost IP1 on a wordpress website and this works fine.
DNS are recorded with two ns of bluehost only.
Based on my understanding I should point the erp.example.com to IP2, then set nginx to filter erp.example.com to go to IP2:port with a redirection ?
I don't understand why my A record pointing to IP2 doesn't direct me to the digital ocean server. In Chrome it gives me a ERR_NAME_NOT_RESOLVED .
What am I doing wrong ?
I think that it could work if you set dns A record to point just one server(one with www) and set the nginx:
- one block to point to Odoo (reverse proxy to IP1 address)
- other to redirect to IP2(your www)
server {
listen 80;
server_name http://erp.example.com;
location / {
proxy_pass http://ipOfYouOdoo:8069;
proxy_redirect off;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_read_timeout 3000000;
client_max_body_size 2000M;
}
}
server {
listen 80;
server_name http://www.axample.com;
location / {
root /var/www/static;
}
}
You're right. You've to point example.com to IP1 and erp.example.com to IP2 through your DNS manager (name.com in your case).
You can't define port in DNS level. You've to configure in nginx with a redirection, since the default http port is 80. You could try proxy_pass alternatively if you don't want to do redirection.
After setting up your A records, try pinging to both domains to make sure it is working. Sometimes it may take some time to reflect the changes due to DNS cache.

nginx Reverse Proxy with plesk

I've already seen some answers on here and none of the solutions seem to work.
I have domain.com with a wordpress install
and a script running on domain.com:6000
I want to be able to have script.domain.com show what's on domain.com:6000
Now the other big issue is plesk. (It gets a lot of hate but the people using the website like the UI.) but here's what I've done/tried
New folder and file in /var/www/vhosts/domain.com/conf
file : vhost_nginx.conf
and what's currently in it
server {
listen 80;
server_name script.domain.com;
location / {
proxy_pass http://domain.com:6000;
}
}
Also having tried
location /script/ {
proxy_pass http://domain.com:6000/;
}
to try and have domain.com/script show something different.
Any suggestions?
Right now in PLesk 12.5 there is no way to override "location /" via plesk, because all custom conf files are added at the end of nginx's server section after default "location /" derectives.
You can create or change hosting type of your subscription to forwarding like in this answer https://serverfault.com/a/541055/154664
But in this case port will be visible in URL.
Another solution is to create your own custom virtual host in nginx in some separate config - it's actually easiest way now.
Another solution is to customize virtual hosting templates, but it's too much side effects on Plesk upgrade.
I put this in the Plesk UI under additional nginx directives and it worked for me. You can remove the if, if you are ok with http traffic. Also replace <*> accordingly. For instance:
<your-domain> = script.domain.com, <your-host> = localhost <your-port> = 6000
if ($scheme = http) {
return 301 https://<your-domain>;
}
location ~ / {
proxy_pass http://<your-host>:<your-port>;
proxy_redirect off;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Host $server_name;
}

Change Host header in nginx reverse proxy

I am running nginx as reverse proxy for the site example.com to loadbalance a ruby application running in backend server. I have the following proxy_set_header field in nginx which will pass host headers to backend ruby. This is required by ruby app to identify the subdomain names.
location / {
proxy_pass http://rubyapp.com;
proxy_set_header Host $http_host;
}
Now I want to create an alias beta.example.com, but the host header passed to backend should still be www.example.com otherwise the ruby application will reject the requests. So I want something similar to below inside location directive.
if ($http_host = "beta.example.com") {
proxy_pass http://rubyapp.com;
proxy_set_header Host www.example.com;
}
What is the best way to do this?
You cannot use proxy_pass in if block, so I suggest to do something like this before setting proxy header:
set $my_host $http_host;
if ($http_host = "beta.example.com") {
set $my_host "www.example.com";
}
And now you can just use proxy_pass and proxy_set_header without if block:
location / {
proxy_pass http://rubyapp.com;
proxy_set_header Host $my_host;
}
map is better than set + if.
map $http_host $served_host {
default $http_host;
beta.example.com www.example.com;
}
server {
[...]
location / {
proxy_pass http://rubyapp.com;
proxy_set_header Host $served_host;
}
}
I was trying to solve the same situation, but with uwsgi_pass.
After some research, I figured out that, in this scenario, it's required to:
uwsgi_param HTTP_HOST $my_host;
Hope it helps someone else.
Just a small tip. Sometimes you may need to use X-Forwarded-Host instead of Host header. That was my case where Host header worked but only for standard HTTP port 80. If the app was exposed on non-standard port, then this port was lost when the app generated redirects. So finally what worked for me was:
proxy_set_header X-Forwarded-Host $http_host;

Resources