I have a PHP/MySQL website hosted on an Ubuntu 16.04 server, for example on the domain www.website.com, and I would like a "sub-folder" of that same domain, to be hosted on a separate server.
For example:
http://www.website.com is hosted on server IP 1.1.1.1
And I would like
http://www.website.com/another-site/ to be hosted on server IP 2.2.2.2
Both websites are PHP/MySQL, and both servers are Ubuntu 16.04 and I am using Nginx server blocks to manage the domains.
I have had some success with the following set up on 1.1.1.1, but it doesn't seem to work completely and images and css files on the site 404:
location /another-site {
proxy_pass http://2.2.2.2:80;
proxy_set_header Host another-site.dev;
proxy_set_header X-Forwarded-For $remote_addr;
}
And then on the 2.2.2.2 server:
server {
listen 80;
server_name another-site.dev;
root /var/www/another-site;
index index.php;
...
Am I on the right lines, or is there a simpler way of achieving this? I don't want to resort to having both sites on the same server if I can help it.
proxy_pass http://2.2.2.2:80; requires a slash at the end proxy_pass http://2.2.2.2:80/; or it only loads the index.
Related
I'm having a problem with nginx server.
When I deploy it and type my hostname in the broker window it will find the page, but it will display IP, not the host name. I tried few things and it always fails. It is strange because I used this before and worked.
I can add that I'm using it as a reverse proxy.
DNS correctly redirects to IP.
But no hostname is shown.
I tried this on AWS EC2 and on digital ocean.
My basic conf is:
server {
listen 80;
listen [::]:80;
server_name hostname.com;
location / {
proxy_pass http://api:8000/index;
proxy_set_header Upgrade $server_name;
proxy_set_header Host $server_name;
}
}
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.
Consider two websites hosted on the same server: domain.com and foo.domain.com. I want to start up a monitoring panel for each site on port 5555. Each site has a separate monitoring panel so I need to use nginx to route domain.com:5555 and foo.domain.com:5555 to two different places.
Here is the configuration for foo.domain.com:
server {
listen 5555;
server_name foo.domain.com;
location / {
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $http_host;
proxy_redirect off;
proxy_pass http://localhost:5678;
}
}
While this works fine for foo.domain.com:5555, it is also routing domain.com:5555 to the monitoring panel. This is acting like I had defined server_name domain.com foo.domain.com, but clearly I only defined it for foo.domain.com.
The only other nginx configs on the server are for ports 80 and 443. Neither of those configs use any wildcards and explicitly use the full name.
nginx always has a default server - if you do not define a default server, it will use the first server block with a matching listen directive.
If you want to discourage this behaviour, you will need to define a catch-all server for port 5555.
For example:
server {
listen 5555 default_server;
return 444;
}
See this document for more.
I am setting up gogs on nginx server.I also have cpanel/apache hosted on the same server.I am redirecting my gogs call using .htaccess from cpanel.My nginx configuration is
server {
listen 9800;
server_name <my_domain>;
proxy_set_header X-Real-IP $remote_addr; # pass on real client IP
location / {
proxy_pass http://localhost:8000;
}
}
It is working fine if i am using direct ip from browser but when i am using domain it throwing ERR_TOO_MANY_REDIRECTS error on browser.
suppose i Have a server on ip 111.111.111.111
on which nginx server is installed as a web server
I want that if someone visit on
http://111.111.111.111/new
They should see the content of
http://example.github.io/new
Someone told me it is possible via NGINX Reverse Proxy or Apache Reverse Proxy
The trick of configuring sites-enabled/default works fine for locally hosted sites on different port but it is not working for external website.
What i have done for this (on server 111.111.111.111):
in /etc/nginx/sites-enabled/default
server {
listen 80;
location /new/ {
proxy_pass http://example.github.io/new;
proxy_redirect default;
proxy_buffering 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-Protocol $scheme;
}
}
What i got :
404
There isn't a GitHub Pages site here.
GitHub Pages allows repository owners to associate a domain with that repository, which it verifies by making sure that domain's A/CNAME records are pointed to GitHub.
If you are pointing the entirety of your domain to this GitHub page, then you do not need a reverse proxy, as the A records will accurately point your domain to GitHub Pages.
Your configuration aims to only reverse proxy a directory of your domain, instead of your domain as a whole. However, you are setting your Host header to match the Host header as requested by the client. As a result, GitHub Pages is checking if that repository is configured to receive traffic as 111.111.111.111, which it is not. This is why you receive the 404 error -- there is not a GitHub Pages configuration that matches that repository and host combination.
Change the Host header in proxy_set_header to example.github.io so that, even though the client requested 111.111.111.111, GitHub receives the request as a request for example.github.io.