<![CDATA[ Need help with nginx directives for MODX Cloud - My Forums]]> https://forums.modx.com/thread/?thread=82505 <![CDATA[Re: Need help with nginx directives for MODX Cloud]]> https://forums.modx.com/thread/82505/need-help-with-nginx-directives-for-modx-cloud#dis-post-455457
# x-ua-xompatible header
add_header X-UA-Compatible IE=edge,chrome=1;



if ($host = "static.chsmedien.com") {
  rewrite ^ /assets$uri;
}



location ~ ^(/assets/images/[^\.]+)(\.(?:jpe?g|png|gif))$ {
    expires 365d;
    
    # Serves static files in high resolution only if required
	# Naming convention for high resolution images:
	# [filename]@2x[extension], e.g.:
	# [email protected]
	set $hidpi_uri $1@2x$2;

	if ($http_cookie !~ 'device-pixel-ratio=2') {
    	# If the device-pixel-ratio cookie is not set to 2, fall back to
    	# default behaviour, i.e. don't try to serve high resolution image
    	break;
    }
	
	# device-pixel-ratio cookie is set to 2
	# Serve high resolution image if available,
	# otherwise fall back to standard resolution
	try_files $hidpi_uri $uri =404;

}



location ~* \.(?:js|css)$ {
	expires 30d;
}



# rewrite blog/rss to feedburner
rewrite  ^/blog/rss$  http://feeds.feedburner.com/chsmedien  permanent;



# modx furls rewrite
location / {
	try_files $uri $uri/ @modx-rewrite;
}


The only thing that is missing is filename-based chaching rewrites:
# Built-in filename-based cache busting
# This will route all requests for /css/style.20120716.css to /css/style.css
# Read also this: https://github.com/h5bp/html5-boilerplate/blob/master/doc/htaccess.md#cache-busting
location ~* (.+)\.(\d+)\.(js|css)$ {
	try_files $uri $1.$3;
}

This would be again in confilct with the existing location block for css/js files. But I currently have no idea how to combine them.]]>
christianseel Feb 17, 2013, 10:51 AM https://forums.modx.com/thread/82505/need-help-with-nginx-directives-for-modx-cloud#dis-post-455457
<![CDATA[Re: Need help with nginx directives for MODX Cloud]]> https://forums.modx.com/thread/82505/need-help-with-nginx-directives-for-modx-cloud#dis-post-455450 Your suggestion works, as far as I can see. But the retina rewrite still doesn't work.

My complete rules now:
# x-ua-xompatible header
add_header X-UA-Compatible IE=edge,chrome=1;


if ($host = 'static.chsmedien.com') {
  rewrite ^ /assets$uri last;
}


# expire headers for assets
# 1: images
location ~ ^(/images/[^\.]+)(\.(?:jpe?g|png|gif))$ {
    expires 355d;
    
    # Serves static files in high resolution only if required
	# Naming convention for high resolution images:
	# [filename]@2x[extension], e.g.:
	# [email protected]
	set $hidpi_uri $1@2x$2;

# disable this for testing...	
#	if ($http_cookie !~ 'device-pixel-ratio=2') {
    	# If the device-pixel-ratio cookie is not set to 2, fall back to
    	# default behaviour, i.e. don't try to serve high resolution image
#    	break;
#    }
	
	# device-pixel-ratio cookie is set to 2
	# Serve high resolution image if available,
	# otherwise fall back to standard resolution
	try_files hidpi_uri $uri =404;

}
# 2: js/css
location ~* \.(?:js|css)$ {
	expires 30d;
}



# Built-in filename-based cache busting
# This will route all requests for /css/style.20120716.css to /css/style.css
# Read also this: https://github.com/h5bp/html5-boilerplate/blob/master/doc/htaccess.md#cache-busting
location ~* (.+)\.(\d+)\.(js|css)$ {
	try_files $uri $1.$3;
}



# rewrite blog/rss to feedburner
rewrite  ^/blog/rss$  http://feeds.feedburner.com/chsmedien  permanent;



# modx furls rewrite
location / {
	try_files $uri $uri/ @modx-rewrite;
}
]]>
christianseel Feb 17, 2013, 07:49 AM https://forums.modx.com/thread/82505/need-help-with-nginx-directives-for-modx-cloud#dis-post-455450
<![CDATA[Re: Need help with nginx directives for MODX Cloud]]> https://forums.modx.com/thread/82505/need-help-with-nginx-directives-for-modx-cloud#dis-post-455445
if ($host = "www.chsmedien.com") {
  rewrite ^ $scheme://chsmedien.com$uri permanent;
}
]]>
jonleverrier Feb 17, 2013, 06:10 AM https://forums.modx.com/thread/82505/need-help-with-nginx-directives-for-modx-cloud#dis-post-455445
<![CDATA[Re: Need help with nginx directives for MODX Cloud]]> https://forums.modx.com/thread/82505/need-help-with-nginx-directives-for-modx-cloud#dis-post-455360
I think I can help with the first problem.

Your test to see if the $host is "static.chsmedien.com" is in the location / {} block. However, any requests for assets are probably matching your (?:ico|gif|jpe?g|png) or js|css location blocks. Only one location block is used for a request, unless the request is rewritten.

I would suggest moving this conditional out of a location block altogether (i.e. to near the top of the rules), and doing a rewrite instead:

if ($host = 'static.chsmedien.com') {
  rewrite ^ /assets$uri last;
}


Hope this helps.
]]>
netProphET Feb 16, 2013, 12:21 AM https://forums.modx.com/thread/82505/need-help-with-nginx-directives-for-modx-cloud#dis-post-455360
<![CDATA[Re: Need help with nginx directives for MODX Cloud]]> https://forums.modx.com/thread/82505/need-help-with-nginx-directives-for-modx-cloud#dis-post-455320 christianseel Feb 15, 2013, 02:08 PM https://forums.modx.com/thread/82505/need-help-with-nginx-directives-for-modx-cloud#dis-post-455320 <![CDATA[Re: Need help with nginx directives for MODX Cloud]]> https://forums.modx.com/thread/82505/need-help-with-nginx-directives-for-modx-cloud#dis-post-455312 jonleverrier Feb 15, 2013, 01:05 PM https://forums.modx.com/thread/82505/need-help-with-nginx-directives-for-modx-cloud#dis-post-455312 <![CDATA[Re: Need help with nginx directives for MODX Cloud]]> https://forums.modx.com/thread/82505/need-help-with-nginx-directives-for-modx-cloud#dis-post-455310 jonleverrier Feb 15, 2013, 12:57 PM https://forums.modx.com/thread/82505/need-help-with-nginx-directives-for-modx-cloud#dis-post-455310 <![CDATA[Need help with nginx directives for MODX Cloud]]> https://forums.modx.com/thread/82505/need-help-with-nginx-directives-for-modx-cloud#dis-post-455296 Hi,

I have 2 problems with rewrites for MODX Cloud:

1. Rewrite static.mydomain.com to assets folder

I want this subdomain to point to the /assets/ folder of my Cloud. I tried to set the root for this subdomain like this:
location / {
	
	if ($host = 'static.chsmedien.com') {
		root /paas/cxxxx/www/assets/;
	}
	
	try_files $uri $uri/ @modx-rewrite;
}

...but this is not working.


2. Send retina images based on cookie

Based on this http://shauninman.com/tmp/retina/, I'm setting a cookie in the browser and the webserver should send @2x images. But this doesn't work, too.
location ~* \.(?:ico|gif|jpe?g|png)$ {
    expires 355d;
    
    # Serves static files in high resolution only if required
	# Naming convention for high resolution images:
	# [filename]@2x[extension], e.g.:
	# [email protected]
	set $hidpi_uri $1@2x$2;
	
	if ($http_cookie !~ 'device-pixel-ratio=2') {
    	# If the device-pixel-ratio cookie is not set to 2, fall back to
    	# default behaviour, i.e. don't try to serve high resolution image
    	break;
    }
	
	# device-pixel-ratio cookie is set to 2
	# Serve high resolution image if available,
	# otherwise fall back to standard resolution
	try_files $hidpi_uri $uri =404;

}



My complete rules:
# x-ua-xompatible header
add_header X-UA-Compatible IE=edge,chrome=1;



# expire headers for assets
# 1: images
location ~* \.(?:ico|gif|jpe?g|png)$ {
    expires 355d;
    
    # Serves static files in high resolution only if required
	# Naming convention for high resolution images:
	# [filename]@2x[extension], e.g.:
	# [email protected]
	set $hidpi_uri $1@2x$2;
	
	if ($http_cookie !~ 'device-pixel-ratio=2') {
    	# If the device-pixel-ratio cookie is not set to 2, fall back to
    	# default behaviour, i.e. don't try to serve high resolution image
    	break;
    }
	
	# device-pixel-ratio cookie is set to 2
	# Serve high resolution image if available,
	# otherwise fall back to standard resolution
	try_files $hidpi_uri $uri =404;

}
# 2: js/css
location ~* \.(?:js|css)$ {
	expires 30d;
}



# Built-in filename-based cache busting
# This will route all requests for /css/style.20120716.css to /css/style.css
# Read also this: https://github.com/h5bp/html5-boilerplate/blob/master/doc/htaccess.md#cache-busting
location ~* (.+)\.(\d+)\.(js|css)$ {
	try_files $uri $1.$3;
}






# modx furls rewrite
location / {
	
	if ($host = 'static.chsmedien.com') {
		root /paas/c0073/www/assets/;
		break;
	}
	
	try_files $uri $uri/ @modx-rewrite;
}
]]>
christianseel Feb 15, 2013, 10:28 AM https://forums.modx.com/thread/82505/need-help-with-nginx-directives-for-modx-cloud#dis-post-455296