I have a ecommerce in Magento: ecommerceshop.com (example) and i create a wordpress blog to this ecommerce.
I have two different servers:
ecommerceshop.com in AWS
blog.ecommerceshop.com (Blog) in Digital Ocean
In SEO issues, isn't a good idea because it doesn't give any relevance, correct?
I need an idea to make my blog as if it were a folder in AWS (tunnel?), but in the Digital Ocean server, for security reasons.
Result:
ecommerceshop.com/blog
ecommerceshop.com/blog/7-things-to-do/
Possibly useful points:
- I'm using NGINX on both servers
UPDATED - SERVER BLOCKS:
blog.ecommerceshop.com server block (Digital Ocean)
server {
listen blog.ecommerceshop.com:80;
root /usr/share/nginx/html;
index index.php index.html index.htm;
server_name blog.ecommerceshop.com;
include /etc/nginx/security.nginx;
location / {
try_files $uri $uri/ /index.php?q=$uri&args;
}
error_page 404 /404.html;
location ~ \.php$ {
try_files $uri =404;
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_pass unix:/var/run/php5-fpm.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
}
ecommerceshop.com server block (AWS)
server {
listen 8082;
root /mnt/www/sites/ecommerceshop;
index index.php;
server_name www.ecommerceshop.com;
location ~ .php$ { ## Execute PHP scripts
if (!-e $request_filename) { rewrite / /index.php last; }
add_header X-Cache $upstream_cache_status;
expires off; ## Do not cache dynamic content
fastcgi_pass unix:/var/run/php5-fpm.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param MAGE_RUN_TYPE website;
fastcgi_param MAGE_RUN_CODE base;
include fastcgi_params; ## See /etc/nginx/fastcgi_params
}
}
2 Answers 2
The solution is to point ecommerceshop.com to your Digital Ocean instance and add a server block for it. The idea is to reverse proxy back to the AWS instance.
server {
listen 80;
server_name blog.ecommerceshop.com;
return 301 $scheme://ecommerceshop.com/blog/$request_uri;
}
server {
listen 80;
server_name ecommerceshop.com;
index index.php index.html index.htm;
include /etc/nginx/security.nginx;
location / {
proxy_pass x.x.x.x:8082;
proxy_set_header Host $host;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_set_header Accept-Encoding "";
}
location /blog {
rewrite ^/blog(.*)$ /html1ドル last;
}
location /html {
internal;
root /usr/share/nginx;
try_files $uri $uri/ /html/index.php?q=$uri&args;
error_page 404 /404.html;
location ~ \.php$ {
try_files $uri =404;
fastcgi_pass unix:/var/run/php5-fpm.sock;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
}
}
You will also need to change the location of the WordPress blog, by either editing the wp-config.php and adding something like:
define( 'WP_SITEURL', '/blog' );
define( 'WP_HOME', '/blog' );
Or changing these values in the general setting of the admin panel.
I've used an internal rewrite to make use of the html directory name (and avoid using alias - which can cause problems). But you may want to rename the html directory to blog and eliminate that step.
I have redirected users of blog.ecommerceshop.com to ecommerceshop.com/blog, because the old location will not work any more.
I haven't tested this, so there may be a couple of typos - good luck.
I have 2 suggested approaches to achieve this.
Similar to Richards suggestion, you could reverse proxy traffic for one of these sites to the other. I would go the other way though as I assume your ecommerce store is the primary site and you don't want an outage of your blog server affecting your sales. e.g send all your traffic through the ecommerceshop.com domain and set up a reverse proxy on your AWS nginx to direct traffic under /blog to your blog server.
Alternatively you could use a third party Magento extension, Fishpig Wordpress Integration. You can set this up to render your Wordpress blog posts through your Magento theme layer, it just needs to have access to the Wordpress database. Your Wordpress install really just becomes the admin UI to create posts for your Magento site. The good thing about this approach is that you don't have to have Wordpress public facing anymore, e.g you could restrict it to your IP or use HTTP authentication to restrict access. Therefore affectively eliminating Wordpress as an attack vector.
ecommerceshop.comto your Digital Ocean instance and add aserverblock for it, thenproxy_passthelocation /block back to the AWS instance. No need to change the name of the AWS instance (it can continue to believe it is the one trueecommerceshop.com- but you may need to refer to it by IP address). The WP blog should be moved to a sub directory by changing WP_SITEURL and WP_HOME, and access it from alocation ^~ /blogblock. If you would like more detail, post yourserverblock forblog.ecommerceshop.com