Q:

Create link to Wordpress blog from MEANJS app in the same domain nginx

I am running a Node app at port 3000, which my Nginx server is successfully redirecting to from port 80. But within my Node app I have a wordpress blog which I am running using Apache at port 8080. I am unable to link node app to this blog, and keep getting a 404 error. 
I had used:
sudo iptables -t nat -A PREROUTING -i eth0 -p tcp --dport 80 -j REDIRECT --to-port 3000

Here are the things I have done:

Set up my nginx to redirect to 127.0.0.1:8080 on /blog
server {
location / {
    proxy_pass http://127.0.0.1:3000;
   }
location /blog {
    proxy_pass http://127.0.0.1:8080;
   } 
 }
Pointed my Apache to 8080 to root folder of wordpress at /var/www/htdocs
Within my MEAN app link blog with a target=_self
[NOTE: have also tried ng-click="$event.stopPropagation()" and window.location= '/blog' on ng-click]

Now I keep getting redirected to /blog#!/ and given a 404 error within my app itself. Being my first MEAN app, I am a little new to this, so please bear with me if the answer is obvious, cause I fail to see it.
EDIT: Apparently I haven't set up Apache correctly as I cannot access anything at port 8080, when trying to access myip:8080 from the outside
EDIT 2: So now I can successfully access the blog at port 82, and have set up my wordpress site. Now nginx is not detecting the url mydomain.com/blog as it is not redirecting it and Node continues to handle by url giving a 404 error, though if I enter mydomain.com:82 it takes me there, which then changes to the ip:82 format on clicking on anything. :(( This is really driving me up the wall

A:

So I finally solved this one :). Here is my solution in case some one wants to add a Wordpress blog to their MEAN JS app.
My set up is a Debian OS running an Nginx server as the main web server, so at port 80. My node app is set up to run at port 3000, and even though I don't think a third server is needed, I went with it anyways, an Apache server at port 82, for my Wordpress blog.
Now before I added the blog, I was redirecting all traffic from port 80 to 3000 by setting a prerouting rule in iptables
sudo iptables -t nat -A PREROUTING -i eth0 -p tcp --dport 80 -j REDIRECT --to-port 3000

This has to be deleted before your Nginx can handle anything. So I went to my NAT iptables, and deleted this rule by line number. I did the following
iptables -L -t nat –line-numbers

To see my list of prerouting rules and get the correct line number and then deleted it with
iptables -t nat -D PREROUTING MYRULELINENUMBER

After this I set up my nginx server by adding a file example.com in sites-available folder at etc/nginx/sites-available/
upstream app_node{
 server 127.0.0.1:3000;
 keepalive 8;
}
server{
 listen 0.0.0.0:80;

 server_name example.com;
 access_log /path/to/log;

 location / {
   proxy_pass http://app_node;
   //Other lines here do a basic Nginx setup search you can find them all
 }

 location /blog{
   proxy_pass http://127.0.0.1:82;
 }

After this I linked this file to my nginx/sites-enabled to get it going
sudo ln -s /etc/nginx/sites-available/example.com /etc/nginx/sites-enabled/example.com

Now my nginx is all set up, moving on to my blog. I first installed Wordpress in var/www/myblog/ and then went to my etc/apache2/sites-available folder
If you don't know how to install Wordpress on debian, look at the end of this post, I have attached all the links I used
My example.com file in apache2/sites-available
<VirtualHost *:82>
 ServerName example.com
 DocumentRoot /var/www/myblog
 Alias /blog /var/www/myblog

 <Directory /var/www/myblog>
   Options FollowSymLinks
   AllowOverride All
   Order allow,deny
   allow from all
 </Directory>

I would suggest copy default under sites-available and customize for your own domain.
Finally in my angular file, I linked blog with a simple
<a href="http://example.com/blog" target="_self">BLOG</a>

Nginx will route you to Apache on clicking this link, you set up your blog by visiting mydomain.com/blog/wp-admin, make sure your SiteUrl and Wordpress Url are set up correctly, I personally spent too long fixing this as I messed up here. 
If you run into any trouble try running a 
wget example.com/blog

It will show you exactly what is happening when the request is received by your nginx server. I had a stray rewrite in my nginx server file causing a 301 error, so make sure your correct examples.com file is available in sites-enabled.
Links that helped immensely:
https://www.binarylane.com.au/support/solutions/articles/1000017339-installing-wordpress-on-debian-ubuntu
http://lubos.rendek.org/remove-all-iptables-prerouting-nat-rules
http://nginx.org/en/docs/http/ngx_http_proxy_module.html
https://askubuntu.com/questions/162866/correct-permissions-for-var-www-and-wordpress
https://www.linode.com/docs/websites/nginx/basic-nginx-configuration
http://www.cyberciti.biz/faq/linux-unix-bsd-nginx-413-request-entity-too-large/
http://httpd.apache.org/docs/1.3/urlmapping.html
Hope this helps someone!!

