Nginx proxy pass (not redirect) - nginx

I have a nginx server that runs drupal. We're changing the way our site runs. I want user.redangus.org to pull up the same page that is at redangus.org/user.
My nginx right now is resulting in a redirect to redangus.org/user, but I want the URL to stay as user.redangus.org
My nginx for this currently looks like:
# user.redangus.org
server {
listen 80;
server_name user.redangus.org;
location / {
proxy_pass http://127.0.0.1/user$request_uri;
proxy_set_header Host redangus.org;
}
}
How do I get it to pull the page without redirecting to the page?

Related

Nginx rewrite urls to match proxy address

I am running a wordpress docker container , the site is accessible through host machines port 8000 , if go to localhost:8000 boom i get to see my wordpress site.
It's boring to always type localhost:8000 to see my website, so i decided to commission nginx as a reverse proxy for my site. I've set up a virtual host in nginx that has the name proxy.site , i can now access by wordpress site by visiting http://proxy.site.
Up until this point, we are doing great, when http://proxy.site opens up, i can see a list of my blog posts, lets say i want to read my latest blog post about COVID-19 , when i click on the link, ohohohoho it opens up as http://localhost:8000/posts/covid19
I want it to open with the proxy url as in http://proxy.site/posts/covid19 , i need to whole site to be accessible through the http://proxy.site site name,
I need nginx to rewrite all my links in localhost:8000/* to proxy.site/* , no body loves typing ports when accessing a blog,
Here is how my nginx conf file looks like
server {
listen 80;
listen [::]:80;
root /var/www/proxy.site/html;
index index.html index.htm index.nginx-debian.html;
server_name proxy.site www.proxy.site;
location / {
proxy_pass http://localhost:8000;
#proxy_set_header HOST $host;
#proxy_redirect http://localhost:8000/ http://proxy.site/ ;
#try_files $uri $uri/ =404;
}
}
How do i achieve rewrite all urls in the proxied site with my custom host name ?
Nginx does not listen to localhost:8080, nginx will not inspect links from your site to rewrite them, you should find a way on WordPress to replace base url of your links.based on the environment

Serve virtuoso opensource behind a nginx proxy

I have a virtuoso-opensource instance on localhost:8890
I have configured a nginx proxy to redirect at localhost/virtuoso
location /virtuoso {
proxy_pass http://localhost:8890/;
proxy_set_header Host localhost;
}
The main page of virtuoso is redirected but CSS and images are not. And when a go to /virtuoso/conductor, it redirect me to /conductor.
how can I properly configure nginx to get the right redirection?

Nginx reverse proxy configuration multi domains virtualhost

I'm having trouble configuring my nginx proxy despite reading a number of guides and trying for three consecutive evenings.
Here is my topology:
(From internet) All traffic from port 80 is redirected to 192.168.1.4, a ubuntu-server virtual running nginx.
I have a NAS which has a subdomain myName.surname.com which connects to the admin page. On that NAS, I have apache webserver running hosting a couple of sites on port 81, 82,
The NAS uses virtualhosts, so domains successfully redirect (without using nginx).
I also have an ASP.NET website running on IIS on another 192.168.1.3:9810.
Now here is my NGINX configuration. I tried configuring it a few times but broke it so I've put it back to its default state:
server {
listen 80 default_server;
root /usr/share/nginx/html;
index index.html index.htm;
server_name localhost;
location / {
proxy_pass http://192.168.1.1; #WORKS OK
}
}
If I go on myName.surname.com or wordpressWebsite.co.uk or myIISSiteDomain.co.uk I am with config above greeted with the correct page at 192.168.1.1:8080 OR 192.168.1.1:81.
It's a start.
First problem is When I navigate to any other page (not home page) like wordpressWebsite.co.uk/blog, it breaks giving 404. So I have tried to differentiate between URLs? I read that the config should be something like:
server {
listen 80;
server_name wordpressWebsite.co.uk;
location / {
proxy_pass http://192.168.1.1:81;
}
}
server {
listen 80;
server_name myName.surname.com;
location / {
proxy_pass http://192.168.1.1;
}
}
server {
listen 80 myIISSiteDomain.co.uk
location / {
proxy_pass http://192.168.1.3:9810;
}
}
But this is not quite right.
1) wordpressWebsite.co.uk loads up the page, but as soon as I go to any other link like wordpressWebsite.co.uk/blog it breaks, giving me my NAS error message like its trying to access 192.168.1.1/blog rather than the virtualhost ~/blog. It actually changes my URL in navbar to 192.168.1.1 so why is it behaving like this?
2) if I'm using virtual host, I don't think I should need to pass in the port via nginx for 192.168.1.1:81 (wordpressWebsite.co.uk). Surely I just need to point it to 192.168.1.1, and then virtualhost should detect that the url maps to 81? I'm not sure how to to do this as I don't fully understand what actually gets passed from nginx to the server?
You can add try_files $uri $uri/ /index.php?$args;
See this https://www.geekytuts.net/linux/ultimate-nginx-configuration-for-wordpress/

How to access minicron using Nginx at specified URL

I've installed minicron from https://jamesrwhite.github.io/minicron/ on an ubuntu aws server with Nginx and when I don't specify a directory in location, the primary url is redirected to the Cron page as expected. However, if I add 'minicron' to the location as you see below, I get "Sinatra doesn't know this ditty" error. I'm at a lost and google hasn't been any help for either of these problems. My main goal is just to get minicron to load at a separate sub domain or directory than the main url. Any help would be appreciated.
http{
...
server {
# The port you want minicron to be available, with nginx port 80
# is implicit but it's left here for demonstration purposes
listen 80;
# The host you want minicron to available at
server_name *.com;
location /minicron {
# Pass the real ip address of the user to minicron
proxy_set_header X-Real-IP $remote_addr;
# minicron defaults to running on port 9292, if you change
# this you also need to change your minicron.toml config
proxy_pass http://127.0.0.1:9292;
}
}
}
Currently the URI /minicron is being sent upstream to http://127.0.0.1:9292/minicron. Your previous test would have hit http://127.0.0.1:9292/.
You need to rewrite the URI before sending it upstream. Maybe:
location /minicron/ {
...
proxy_pass http://127.0.0.1:9292/;
}
location = /minicron { rewrite ^ /minicron/ last; }
See this and this for details.

nginx reverse proxy, single domain, multiple subdirectories

Having trouble figuring this out.
I have nginx running on home.domain.com.
Within my home network, I have multiple web services that I'd like to access externally through a reverse proxy. No SSL for now, but I'll add that later. I need to set up a reverse proxy on subdirectories of home.domain.com/app{1-3} as I only have a valid cert for home.domain.com.
My current configuration:
server {
listen 80 default;
keepalive_timeout 120;
server_name home.domain.com;
location /app1/ {
proxy_pass http://internalIP1:8081/;
}
location /app2/ {
proxy_pass http://internalIP2:5000/;
}
}
When I try to access home.domain.com/app1, it should redirect to home.domain.com/app1/login/?next=%2F, but instead goes to home.domain.com/login/?next=%2F. This obviously throws a 404, as it's not available on the nginx server.
Thoughts? Suggestions?

Resources