Hi there, I need someone who has experience with Nginx and can help with an nginx config file to get some redirections setup. Thanks,
if you post your actual problem, what exactly you want to achieve and supply enough information about your environment, then I'm sure someone will help you with this or at least point you to the right direction. anyhow, what kind of redirection you want to setup?
At the moment we have this: # nginx configuration location / { if ($http_host !~ "static([0-9]+)\."){ rewrite ^(.*)$ htp://www.domain.com break; } if ($http_host ~ "static([0-9]+)\."){ rewrite ^(.*)$ htp://www.domain.com$request_uri redirect; } } ...and we need this edited so that it will redirect all calls to static.domain.com to the main domain, EXCEPT for images.. in case of images it needs to check if the file exists on static.domain.com/imagepath and if it does it loads it from there, if it doesnt exist there it loads it from domain.com/imagepath
I'm not sure if I understand you well, but anyhow you should do something like this: server { listen 80; server_name mydomain.com; .... .... location ~ /test { try_files http://www.google.com$uri $uri/ @img_pass; } location @img_pass { rewrite ^(.*)$ http://yahoo.com$uri last; } } Code (markup): in this example, this means if I go to mydomain.com/test/not-here.jpg, it will first test if the file requested is available at http://www.google.com/test/not-here.jpg then it will proceed checking it at http://www.google.com/test/not-here.jpg/ and if it is not present there it will do the '@img_pass' which means will look for the file at http://yahoo.com/test/not-here.jpg .
Try adding the following lines to your 'static.domain.com' configuration: server { server_name static.domain.com listen 80; location / { if ($request_uri ~* ^/images) { break; } rewrite ^/(.*)$ http://domain.com/$1 permanent; }
Thank you for the help. With the latest code, will that only use the static.domain.com address for image files, and then redirect all other requests to the main domain.com? Or is it set to only load content from static.domain.com/images?
Ok thank you, I will get this tested now. Is it ok to change: rewrite ^/(.*)$ http://domain.com/$1 permanent; to rewrite ^/(.*)$ http://www.domain.com/$1 permanent; ?