hi i have nginx server and other webserver which i want to hide from public direct access. but when i try to access that server on root i send redirect response to client to url like this: server/test/spring/main. when i try to access it from nginx server i get the server url redirect instead nginx url.
example:
my-nginx.com
my-server.com
if i want to access myserver.com/test/spring/main from nginx server i guess i have to access my-nginx.com/test/spring/main but when i do that i get redirect to url myserver.com...
my config:
upstream my-server {
server my-server.com;
}
server {
listen 80;
server_name my-nginx;
location / {
proxy_pass http://my-server/;
}
}
the other think is when i access the root page on my-server.com i redirect the client to "https://my-server.com/test/spring/main".
Why i'm redirect from my-nginx.com url to my-server.com?
This configuration seems do not have big problem, and I also use proxy_pass to access other domain in our production environment, and do not redirect.
You should be care of the last '/' in "http://my-server/", usint "http://my-server" instead, or just using "http://my-server.com" with no upstream.
The behavior with '/' or with not '/' is a little different.
Related
I just migrated my web app from a server that was using Apache to a new server using Nginx. Everything is fine, except for my API routes.
I'm testing with POSTMAN, and if I use https://www.example.com/api/example I just get a response with an empty "message" variable.
But if I use https://example.com/api/example, it works fine.
I have a mobile app pointing to the URL which includes WWW, and I don't want to make an update just to make this change. How can I make the route including WWW work again?
You need to change the host name in nginx config file to include www.
Sample:
server {
listen 80;
server_name example.org www.example.org;
...
}
I have a fairly simple task, but it doesn't seem to be working and I can't figure out the reason for it. I have a digitalocean droplet and a domain that points to the digitalocean dns. I have set up an "A Record" with "#" and "www" for the domain that both point to my droplet. In my nginx config I have set up one server block for the redirect which contains:
server {
server_name www.example.com;
return 301 $scheme://example.com$request_uri;
}
Now when I do:
curl -I http://www.example.com
I get a http response saying "301 permanently moved" with the correct location. (When I use https I don't get the "permanently moved" but that's a different story).
However when I open the URL in my browser nothing happens and I just get the default nginx website.
What could be the reason for this behavior?
Its correct, you just need a nginx server listening on example.com :
server {
server_name example.com;
location / {
# do something
}
}
Using this tutorial
http://rainbow-six3.com/plesknginx/ i am trying to redirect my name.com to ip:8080 , after that setup if i acces through name.con i get an redirection loop... is there any other service to redirect? Had a lot of problems with nginx.
I want to redirect name.com to an tomcat7 application wich uses ip:8080 to get executed. Tomcat is already an headache...
Neither this helped me:
Tomcat base URL redirection
It outputs webpage not available on link: http://name.com/index.jsp
Mind the words. 'Redirecting' != 'Proying'. You redirect through 301 or 302 to a publicly directly accessible resource, while you proxy to a backend, not supposed to be directly accessed.
The minimal configuration to proxy any name.com/<whatever> request to <ip>:8080/<whatever> is:
server {
listen 80;
server_name name.com;
location / {
proxy_pass $scheme://<ip>:8080;
}
}
We are running Nginx as a proxy in front of a multi-tenant app hosted on IIS. When one of the tenants is down for maintenance I would like to redirect the url to a static web page hosted on AWS S3 or a local static page on the Nginx server.
For example the url may be http://demo.myapp.com, so would want demo to be redirected but anything else such as http://test.myapp.com to function as normal through the proxy pass to the back end web servers.
I have tried using rewrite / return in a new server block setting the server name to demo.myapp.com and this works redirecting to a static page but it redirects all not just demo.
All the traffic goes to port 80 on the Nginx server and the default location / then proxy to the back end web servers.
Looking for any advice on this as I am new to Nginx and cannot find an answer.
Thanks in advance.
Nginx external URL redirect
location ~* ^/example/(.*)$ {
rewrite ^ https://example.net$uri redirect;
}
I'm new to nginx and am trying to figure out an issue with redirection. I'm trying to redirect a website from a host running a web application to another domain. That part I've done but I'm looking to mask it. When it redirects, I don't want the user to know they've gone to another domain.
I've substituted the domain names for privacy of my client. But, they are on a Linode at test.com that's running a web application that's at sub.test.com. All I want is for any user visiting test.com to be redirected to a temporary site hosted on other.com but without exposing the domain.
Previously, someone had shown me how to do it but it was a long time ago and I no longer have the information to reference. Can someone help me out? I don't want to expose the domain of the testing environment.
server {
listen 80;
server_name www.test.com test.com www.test.net test.net;
rewrite ^ http://other.com/sub redirect;
location / {
root /srv/http/www.test.com;
index index.html;
}
}
You can't do that with redirect, cause redirect is actually like telling the browser where to fetch page from, so you can't obscure the real location.
I guess what you need is proxying, e.g. a client requests some document from your server (test.com), then your server fetches the document from some other server (other.com) and returns that document to a client as if it was generated on test.com - it that case a client won't be able to determine where actually the document is originating from.
This can be done with:
server_name test.com;
location / {
proxy_pass http://other.com;
}
if you want the redirect to not change the user-visible domain name then you need to change it from a 301 to a 302 by changing your rewrite as follows:
rewrite ^ http://other.com/sub redirect;