I try to create proxy server using Nginx.
I need configure Nginx that if I request any URL address as client, Nginx must return this URL page immediately. For example I request page using param url from my server:
http://myserver.com/url=www.gogo.com
Nginx should return me page www.gogo.com
I tried in location:
proxy_pass $host
Url should contain the protocal(http/https) later on
Use IP resolver based on url belongs to your intranet or internet
For internet 8.8.8.8
Related
I have a domain. Let's say test.com. I have to forward requests of a route of this domain to a subdomain and render response of the same without Changing URL via Caddy Server
For Example,
Request Flow:
test.com/home -> Caddy -> https://demo.test.com/home
Response Flow:
test.com/home <- Caddy <- https://demo.test.com/home
I tried following reverse_proxy rules to achieve this but was unable to achieve the desired response.
test.com {
reverse_proxy /home https://demo.test.com/home {
#proxy to subdomain
header_up Host demo.test.com
}
}
This crashes the whole site. I think the reason for this is that Caddy doesn't support such type of Upstream Addresses. Valid addresses can be seen here.
Then, I tried the valid one -
test.com {
reverse_proxy /home https://demo.test.com {
#proxy to subdomain
header_up Host demo.test.com
}
}
This didn't led to any error but this didn't bring me any response either. The reason for this can be that I am forwarding the request from Client to another Client and not the actual server.
Hence, I tried to hit the IP address associated with the sub domain
test.com {
reverse_proxy /home <IP-address> {
#proxy to subdomain
header_up Host demo.test.com
}
}
This changes the actual route i.e. in the web-browser it changes the URL from test.com/home to demo.test.com. But it doesn't brought any response either.
Kindly comment if there is any possible solution for forwarding the request to a sub-domain route.
If the solution is not supported by Caddy but by another Web Server, that will also be helpful.
I am completely new to Nginx and php. I have a Baikal self-hosted webserver on my local network and I do not use a DNS. I would like to use it for synchronizing contacts and calendars with my PC and my Android phone.
I have read Nginx tutorial and googled a lot but I still cannot figure out what to use as server-name in nginx and what to use as URL for the client.
I tried :
server_name baikal in Nginx and http://baikal as URL. This works if etc/hosts on the client PC includes baikal. It fails otherwise.
without configuring etc/hosts on the client I tried :
server_name baikal 192.168.1.27/baikal URl
in the client : http://192.168.1.27/baikal produces a 404 error and in the access log Nginx looks for /baikal
What should I use as server name and as url?
On server side
/etc/nginx/sites-available/baikal file must listen on ip address
server {
listen 192.168.1.27:80;
server_name baikal;
root /var/www/baikal;,....
On client side
just type on your browser the ip address 192.168.1.27 and it works
I use wicket 8.10, it is installed on tomcat and proxied by nginx. SSL certificates configured in nginx config. Also Nginx forwards all HTTP requests to HTTPS.
The problem is following:
When I submit any form wicket returns response headers where the Location tag contains url with HTTP protocol.
Why it is important:
The last chrome update makes browser show alert when Location contains HTTP protocol on page opened by HTTPS. Before that, nginx quietly redirected the request, but now user see alert page from browser (similar to when certificate is invalid or absence).
The problem here is that your Wicket application does not know that it is behind a proxy.
There are two solutions:
use XForwardedRequestWrapperFactory
It will wrap the Tomcat's HttpServletRequest with one that reads X-Forwarded-*** request headers.
Just make sure that Nginx exports X-Forwarded-Proto request header
use HttpsMapper
Just overwrite protected Scheme getDesiredSchemeFor(Class<? extends IRequestablePage> pageClass) to return Scheme.HTTPS in PRODUCTION mode and Scheme.HTTP in DEVELOPMENT mode (I assume you don't use Nginx proxy while developing)
The simplest solution I have found is to use the nginx directive:
proxy_redirect http://example.com https://example.com;
It changes location header from http://example.com/any/path to https://example.com/any/path
My issue is that I have a web server running on port 80. I want to use nginx proxy (not the ingress) bto redirect the connection. I want to use link wwww.example.com. How should I tell nginx to proxy the connection on wwww.example.com (which is a different app). I tried using service with load balancer but it changes the hostname ( to some aws link) I need it to be exactly wwww.example.com.
If I understood your request correctly, you may just use return directive in your nginx config
server {
listen 80;
server_name www.some-service.com;
return 301 $scheme://wwww.example.com$request_uri;
}
If you need something more complex check this doc or this
I'm trying to setup an FTP subdomain, such that all incoming SFTP requests to (say) ftp.myname.com, get routed to a particular internal server, (say) 10.123.456 via port 22.
How do I use nginx to route this traffic?
I've already setup the SFTP server, and can SFTP directly to the server, say:
sftp username#123.456.7890, which works fine.
The problem is that when I setup nginx to route all traffic to ftp.myname.com, it connects, but the passwords get rejected. I have no problems routing web traffic to my other subdomains, say dev.myname.com (with passwords), but it doesn't work for the SFTP traffic:
server {
listen 22;
server_name ftp.myname.com;
return .............
}
How do I define the return sting to route the traffic with the passwords?
The connection is SFTP (via port 22).
Thanks
Aswering to #peixotorms: yes, you can. nginx can proxy/load balance http as well as tcp and udp traffic, see nginx stream modules documentation (at the nginx main documentation page) , and specifically the stream core module's documentation.
You cannot do this on nginx (http only), you must use something like HaProxy and a simple dns record for your subdomain pointing to the server ip.
Some info: http://jpmorris-iso.blogspot.pt/2013/01/load-balancing-openssh-sftp-with-haproxy.html
Edit:
Since nginx version 1.15.2 it's now possible to do that using the variable $ssl_preread_protocol. The official blog added post about how to use this variable for multiplexing HTTPS and SSH on the same port.
https://www.nginx.com/blog/running-non-ssl-protocols-over-ssl-port-nginx-1-15-2/
Example of configuring SSH on an upstream block:
stream {
upstream ssh {
server 192.0.2.1:22;
}
upstream sslweb {
server 192.0.2.2:443;
}
map $ssl_preread_protocol $upstream {
default ssh;
"TLSv1.2" sslweb;
}
# SSH and SSL on the same port
server {
listen 443;
proxy_pass $upstream;
ssl_preread on;
}
}