1

I'm facing an issue setting up wordpress with cloudfront.

I've set up all things fine, and it's working, but the problem is that when I send a request, the origin url is displayed in the address bar instead of the cname.

here is my origin vhost configuration :

<VirtualHost *:80>
        ServerAdmin admin@mydomain.com
        ServerName  origin.mydomain.com
        
        DocumentRoot /var/www/mysite.mydomain.com
        <Directory /var/www/mysite.mydomain.com>
                Options -Indexes MultiViews FollowSymlinks
                Options Indexes FollowSymLinks MultiViews
                #AllowOverride AuthConfig
                AllowOverride None
                Order allow,deny
                allow from all
        </Directory>
        <IfModule mod_headers.c>  
                Header unset Server  
                Header unset X-Pingback
                Header unset X-Powered-By  
                Header set Cache-Control "max-age=0, private, no-store, no-cache, must-revalidate"
        </IfModule>  
        ErrorLog ${APACHE_LOG_DIR}/mysite.mydomain.com/error.log


        CustomLog ${APACHE_LOG_DIR}/mysite.mydomain.com/access.log combined

</VirtualHost>

At the cloudfront side I have this for my distribution settings :

Domain Name : d7jz390azoodb9.cloudfront.net
    
Origin : origin.mydomain.net

CNAMEs : mysite.mydomain.com

I made DNS registristions so that :

origin.mydomain.com points to the_public_ip_address_of_myserver

mysite.mydomain.com is a cname of d7jz390azoodb9.cloudfront.net

All the above is working fine. My problem is that, when I enter this in my browser : http//mysite.mydomain.com, I get to my wordpress home page, and from the when I try to navigate, for example clicking on "login" (http://mysite.mydomain/wp-login.php), the url dispayed in my address bar at the top of my page is : http://origin.mydomain/wp-login.php instead, which can be then seen by any user.

If I type myself mysite.mydomain/wp-login.php directly in the browser, I get a Not found from cloudfront.

If I replace the ServerName in my vhost configuration by mysite.mydomain.com I get a Miss from cloudfront.

Do someone know to fix this, so that the url seeing by user always remain mysite.mydomain.com?

Thanks

nixmind
  • 111
  • 1
  • 5
  • I don't see any URL rewrites, so in that case, do you have any configuration done in WordPress to make WP aware it should use the correct subdomain? – JayMcTee Jul 01 '15 at 10:06
  • Yes @JayMcTee . I did this in my wordpress database : UPDATE wp_options SET option_value = replace(option_value, 'http://mysite.mydomain.com', 'http://origin.mydomain.com') WHERE option_name = 'home' OR option_name = 'siteurl'; UPDATE wp_posts SET guid = replace(guid, 'http://mysite.mydomain.com', 'http://origin.mydomain.com'); UPDATE wp_posts SET post_content = replace(post_content, 'http://mysite.mydomain.com', 'http://origin.mydomain.com'); UPDATE wp_postmeta SET meta_value = replace(meta_value,'http://mysite.mydomain.com', 'http://origin.mydomain.com'); – nixmind Jul 01 '15 at 10:27
  • And in my vhost/wordpress root directory, I have this in the **.htaccess** file : `# BEGIN WordPress RequestHeader unset Cookie Header unset Set-Cookie Redirect permanent / http://origin.mydomain.com/ # END WordPress` – nixmind Jul 01 '15 at 10:37
  • Well, then you are redirecting to origin.mydomain instead of mysite.mydomain: "Redirect permanent / http://origin.mydomain.com/" Did you forget to update that redirect? Instead of a blanket redirect, why not match it only if the wrong host is requested? http://stackoverflow.com/questions/5553980/permanent-redirect-via-apache-rewrite-rules – JayMcTee Jul 01 '15 at 10:41
  • No I put this redirect to solve the issue, but it did notthing. – nixmind Jul 01 '15 at 10:55
  • I Don't know if you are really getting my issue. I can access the site, but I don't want the **origin** to be display. I want the url **mysite.mydomain** to remain in my address bar even if behind the right server name is **origin.mydomain.com** – nixmind Jul 01 '15 at 10:59
  • Sure, I get that. But this redirect you have in place tells the webserver to redirect requests for docroot / to origin.mydomain.com but you seem to want to redirect/rewrite to mysite.mydomain.com, which is why I wonder whether that redirect is correct. So instead of "Redirect permanent / origin.mydomain.com/" don't you mean "Redirect permanent / mysite.mydomain.com/" Besides a redirect, I think you probably want to rewrite URLs. – JayMcTee Jul 01 '15 at 11:09
  • I think t the RewriteRule is better. But I've not found the solution. I don't want to break the request process on the server, but I just want the user to see mysite.mydomain for any request in the browser, instead of origin.mydomain. In fact when The user enter mysite.mydomain.com in the browser, the request goes to the cloudfront, and it sends the request to origin.mydomain.com. That's normal and should work like that. But I would like is not to display origin.mydomain.com in the browser `RewriteRule ^origin.mydomain.com/(.*)$ mysite.mydomian.com/$1 [L]` – nixmind Jul 01 '15 at 14:10

1 Answers1

0

The problem was in cloudfront behavior settings.

The configuration I did was good but I told cloudfront not to forward cookies and then the origin server were not receiving any cookie.

I activated all cookies forwarding in cloudfront and it works.

Regards.

nixmind
  • 111
  • 1
  • 5