WordPress with cloudfront , how to mask origin url

amazon-cloudfrontamazon-web-servicesapache-2.2Wordpress

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

Best Answer

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.