Display content of subdomain in root domain - rewriting - .htaccess

I have a landing page hosted at landing.mydomain.com at certain static web host.
My application is running on a server to which mydomain.com is pointing to.
Is there anyway using .htaccess to show display to my visitors the content of landing.mydomain.com when they visit mydomain.com?
If not .htaccess is there a good way to do this. I dont want to move my landing page to my application server just yet. Looking for options. Thanks.

In nginx config you can use this code on domain.com to enable proxy_pass to landing.mydomain.com:
location / {
proxy_pass http://landing.mydomain.com;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
}

Related

URLs Breaking When Hosting Remote Servers Front-End Website on Nginx Proxy

We built an Nginx Server for acting as Edge Proxy for all the ligth weight front-end websites built on different small VMware instances.
The idea is to access the remote server's website like so:
https://nginxserver.mydomain.com/dev/marketing/
And the remote server is configured as upstream in Nginx's config directories:
upstream marketing-dev {
zone marketing-dev-service 64k;
server someserver.mydomain.com:8443;
sticky cookie srv_id expires=1h;
}
And the remote server's dev-marketing.conf file looks like this:
location /dev/marketing/ {
access_log /var/log/nginx/marketing-dev-access.log main;
error_log /var/log/nginx/marketing-dev-debug.log debug;
proxy_pass https://marketing-dev/;
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;
}
When I access the URL, site loads fine, and I can browse to almost all locations and pages within.
Except for few!!
It is dropping the location /dev/marketing/ in the URL and takes me directly to https://nginxserver.mydomain.com/ or takes me to locations by skipping the path.
For example, https://nginxserver.mydomain.com/aboutus instead of https://nginxserver.mydomain.com/dev/marketing/aboutus
Anyway to overcome this?

Nginx - Reverse proxy to an already reverse proxied location or double reverse proxy?

I am using nginx on centos 7.
I am reverse proxying a remote nodejs server on the same LAN to the nginx root / as per the below:
location / {
proxy_pass http://192.168.1.104:3000/;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection 'upgrade';
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
This works fine for serving my website - all external requests on port 80 are rewritten to use https which has been configured in nginx e.g nginx forwards any incoming http requests to https and deals with rewrites and forwarding so that the nodejs content is served over ssl even though ssl hasn't been configured within the node application.
e.g my site can be accessed at https://example.com
I now want to reverse proxy another nodejs app so that it appears at a location which is prefixed with https://example.com e.g: https://example.com/node2/
I've tried using the below config for the second node server...
location /node2/ {
proxy_pass http://192.168.1.100:3000/;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection 'upgrade';
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
When I load the https://example.com/node2/ url, the html of the root page of the second node server is displayed but none of the css, js or images are loaded so the page doesn't look or work as it should and I see the following in the browser console...
Mixed Content: The page at 'https://example.com/node2/' was loaded
over HTTPS, but requested an insecure image
'http://192.168.1.100:3000/assets/graphics/logo.png'. This content
should also be served over HTTPS.
and
Failed to load resource: net::ERR_CONNECTION_CLOSED https://192.168.1.100:3000/assets/css/styles.min.css
for css and js assets... so it seems that no redirection is taking place for assets and also any links on the html page do not show the /node2/ suffix when hovered over or when clicked as the page tries to load the resource from https://example.com instead of https://example.com/node2/
Is it possible to actually do what I want in terms of reverse proxy two locations and can anyone point me in the right direction on how I can get this work as need?
The application being loaded is set up to load assets from the server root, not with server root + /node2/

nginx link nodejs app to subdomain

I have a dropplet on digital-ocean where I have a node.js app and nginx.
So, I installed nginx and then in /etc/nginx/sites-available/ I created a new file called api where I have the following content:
server {
server_name api.my-website.com;
location / {
proxy_set_header X-Real_IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $proxy_host;
proxy_set_header X-NginX-Proxy true;
proxy_pass http://127.0.0.1:9000; // this is where the node app lives
}
}
After I create that I restared nginx but if I go to api.my-website.com I dont see anything (my api has a landing page on /), but if I go to my-website.com:9000 I see the landing that should be on api.my-website.com.
Can someone explain me please what I'm doing wrong?
You did not included your /etc/nginx/sites-available/api file into /etc/nginx/nginx.conf. You need to include /etc/nginx/sites-available/api in /etc/nginx/nginx.conf inside http module and then restart or reload nginx. Your /etc/nginx/nginx.conf may looks like
http {
# other lines for logging, gzip, etc.
# other include may here
# Your include as following
include /etc/nginx/sites-available/api;
}

rewrite nginx subdirectories to local ports

Hi i´m trying to host several sites on one server using nginx. Therefore i want to do the following:
calling www.domainname.com/site1
shall forward to http://localhost:9800
calling www.domainname.com/site2
shall forward to http:/localhost:9801
the local sites are hosted by nodejs with express, so rewriting the paths are necessary.
What i´ve done so far is the this:
location /site1 {
rewrite ^/site1/?(.*)$ /$1 break;
proxy_pass http://127.0.0.1:9800;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
but this only works partly: The stylesheets etc. will not loaded and trying to call
www.domainname.com/site/login
is not working.
Can someone help me writing the correct rewrite ?
Thanks in advance

Nginx second proxy_pass not working

I have nginx, apache, and node setup on my CentOS server.
Node runs on port 8080.
In my default.conf nginx file, I have
location / {
proxy_pass http://127.0.0.1:8080;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
}
That works. When going to my site's homepage (and any other page that node uses, such as /login and /signup page), I see my node app correctly.
I have a couple of other rules like this one, in order to let nginx serve the static files instead of node serving them.
location /javascripts {
root /var/www/myWebsite/public;
}
I am setting up a forum, and I'm using apache and php for it. The forum works at myWebsite.com:90, however I want to make the forum work without the port number.
Apache has Listen 90, and DocumentRoot is set to the forum path.
Nginx conf has this
location /forum {
proxy_pass http://127.0.0.1:90;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
}
But that doesn't work, I get a 404. If I go to some giberrish page, I get the node's error page, so we can see that something is working by getting the 'normal' web 404 instead of my custom node's 404.
How can I remove that :90 port now?
Thanks
upstream apache_server {
server 127.0.0.1:90;
keepalive 60;
}
server {
listen 80;
location / {
proxy_pass http://apache_server
}
}

Resources