2

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
    }
}
4
  • The solution is to point ecommerceshop.com to your Digital Ocean instance and add a server block for it, then proxy_pass the location / 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 true ecommerceshop.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 a location ^~ /blog block. If you would like more detail, post your server block for blog.ecommerceshop.com Mar 3, 2016 at 14:25
  • Thanks, @RichardSmith; I updated the post with blocks, can you check? Mar 3, 2016 at 14:36
  • use DNS, it much easier.
    – MagenX
    Mar 3, 2016 at 14:59
  • +1 for not putting those two on the same domain and keep them separated. A security issue in one of them and both are compromised...
    – 7ochem
    Mar 3, 2016 at 15:07

2 Answers 2

0

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(.*)$ /html$1 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.

0
1

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.

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.