Im trying to do a very basic task of redirecting between two servers based on "http referer".
I have tried a basic If, but I know IF IS EVIL in nginx and didnt manage to make it work, so came up with this solution, of directing based on valid_referer. but Im keep getting 502.
server {
location /application1 {
valid_referers server_names
.click2dad.net*;
if ($invalid_referer){
set $1 '';
proxy_pass http://localhost:8080/$1;
}
}
}
server 2:
server {
listen 8080;
root /home/ubuntu/data/server2;
}
btw I used set $1 = "" , since I kept getting an error if proxy_pass cannot have uri under if statment
Thanks
Make sure you have something running on http://localhost:8080/ .
Do something to check whether port 8080 is used by any process, like
netstat -tulpn | grep 8080
on your terminal.
Related
I'm running Joplin Server on my Raspi4 under http://127.0.0.1:23000 and on the Raspi I can successfully access the web app.
Since I don't want to publish the port 23000, I want Joplin Server to be accessible via https://myRaspi/joplinServer. Therefore I'm using Nginx.
I tried at first with:
location /joplinServer {
proxy_pass http://127.0.0.1:22300;
}
Now when calling https://myRaspi/joplinServer from any other machine, Nginx keeps the subresource /joplinServer, resulting in an "inner call" to http://127.0.0.1:22300/joplinServer - which does not exist, sure, because Joplin Server itself knows nothing about the subresource and seems to have troubles with handling it.
I also tried this:
location = /joplinServer {
rewrite ^/joplinServer?$ http://127.0.0.1:22300 break;
}
But now every external requests to https://myRaspi/joplinServer ends up as http://127.0.0.1:22300 on my machine which does obviously not work.
So what do I have to configure on Nginx to make my setting work?
Thanks in advance!
This post gave me the solution, which looks like this:
location /joplinServer/ {
proxy_redirect off;
rewrite ^/joplinServer/(.*)$ /$1 break;
proxy_pass http://127.0.0.1:22300;
}
I have an Nginx problem and after reading a lot and trying multiple combinations, I do not find the solutions to my problem.
I have a Jira server behind a reverse proxy using Nginx. My problem is that I want to have jira.mydomain.com as the default url but when using support.mydomain.com I want it to redirect to https://jira.mydomain.com/servicedesk/customer/portal/1 because is where the Service Desk. This is what I do not make.
The result that I have now is that both jira.mydomain.com and support.mydomain.com go to the same place which probably is the normal behavior and I do not know how to configure it but if anyone can help would be very appreciated.
Thanks to all of you and the hivemind.
This is what I have right now
/etc/nginx/conf.d/default.conf
upstream jira {
server jira_ip_adress:8081;
}
server {
server_name jira.mydomain.com;
server_name support.mydomain.com;
rewrite ^/support.mydomain.com https://jira.mydomain.com/servicedesk/customer/portal/1;
[...]
location / {
proxy_pass http://jira;
[...]
}
Nginx uses the server_name directive to match the domain name part of a URL. You need to use two server blocks, one for each of the domain names.
For example:
server {
server_name support.mydomain.com;
return 301 https://jira.mydomain.com/servicedesk/customer/portal/1;
}
server {
server_name jira.mydomain.com;
...
}
Obviously, if these are https services, you will need to add the appropriate listen statements to both server blocks.
Use nginx -T (uppercase T) to test the configuration file and view the entire configuration across all included files.
Many many thanks. I tried this yesterday but I had the next error when using nginx -T
nginx: [emerg] unexpected "E" in /etc/nginx/conf.d/default.conf:183
nginx: configuration file /etc/nginx/nginx.conf test failed
I have tried again after your help, and you spotted me in the right direction because today have been able to know what the error was telling to me and fixed.
So know, with your suggestion, is working like a charm.
Thanks a lot!
I am tryin to run nginx latest version with the following configuration, but I get nginx: [emerg] invalid parameter "route=bloomberg" in /etc/nginx/nginx.conf:13
docker run --rm -ti -v root_to_local_nginx_directory:/etc/nginx:ro -p 3080:80 --name=mynginx --entrypoint nginx nginx
# nginx.conf file inside root_to_local_nginx_directory
http {
map $cookie_route $route_from_cookie {
~.(?P<version>w+)$ $route;
}
split_clients "${remote_addr}" $random_route {
50% server bloomberg.com route=bloomberg;
* server yahoo.com route=yahoo;
}
upstream backend {
zone backend 64k;
server bloomberg.com route=bloomberg;
server yahoo.com route=yahoo;
sticky route $route_from_cookie $randomroute;
}
server {
# ...
listen 80;
location / {
proxy_set_header Host $host;
proxy_pass http://backend;
}
}
}
Why is this? According to the documentation this should be correct http://nginx.org/en/docs/http/ngx_http_upstream_module.html#upstream.
The route=string parameter of the server directive within the upstream context is considered to be an enterprise-grade feature, and is thus only available through the commercial subscription, in NGINX Plus, not in OSS NGINX. (If you look closer into the documentation, you'll notice it's grouped together with the other parameters under a separate "available as part of our commercial subscription" subsection.)
Additionally, you're also trying to use some similar "server" parameters within the split_clients context as if they were actual directives interpreted by nginx, even though everything is supposed to be string literals in that context; it's unclear whether or not that part is responsible for any errors, but even if not, it's a bad style to introduce such confusion into your configuration.
References:
http://nginx.org/en/docs/http/ngx_http_upstream_module.html#server
http://nginx.org/en/docs/http/ngx_http_split_clients_module.html#split_clients
https://www.nginx.com/products/nginx/
The reason why you are seeing the error is because the split_clients module does not support the route parameter. Alternatively, you can do something along the lines:
upstream bloomberg {
server bloomberg.com route=bloomberg;
}
upstream yahoo {
server yahoo.com route=yahoo;
}
split_clients "${remote_addr}" $random_route {
50% bloomberg;
* yahoo;
}
I have some Problems with gogs and nginx in my local-Network.
everytime i write "domainname" i mean the hostname of the server
I have little Server running with Openmediavault on it (for NAS) and i also will run some Stuff like gogs. It is running, but only on the URL "http:domainname:3000"
I will have gogs available under git.domainname or gogs.domainname
I have tried so many things, but noting is working.
I have add a config on available Site /enabled-sites (symlink):
server {
listen 80;
server_name git.domainname;
location / {
proxy_pass http://localhost:3000;
}
}
In my gogs Configuration, i have the following Server-Section:
[server]
PROTOCOL = http
DOMAIN = domainname
HTTP_PORT = 3000
ROOT_URL = http://domainname:%(HTTP_PORT)s/
DISABLE_SSH = false
SSH_PORT = 22
START_SSH_SERVER = false
OFFLINE_MODE = true
I have not very much experience in Nginx. so I hope anyone can help me to get this work. Also i hope i get more experience to get work other services in a generic Way to work in subdomain
when any Information is missing to help me, please let me know
I have nginx installed on a Raspberry Pi and this works okay. What I want to do is redirect traffic for a particular port to another server, and have that traffic come back through the Raspberry Pi. I've got the following in my default sites config;
server {
listen 9001;
server_name piweb;
location /transmission {
proxy_pass http://pyrate:9001/$uri$is_args$args;
proxy_set_header Host $host:$server_port;
}
}
But that doesn't work obviously. Is this even possible, or am I barking up the wrong tree?
your configuration seems almost OK, is http://pyrate:9001 accessible from your pi ? did you try with wget or similar tools ?
You should remove the $uri$is_args$args - it passes automatically.
Note that it'll search /transmission/[request] on remote server.