I am stuck with a specific server configuration.
I have a domain: www.domain.com.
I redirect mobiles users to m.domain.com
Until now, no problem.
I want to do not redirect mobile users to m.domain.com on a specific page.
This is what I have now:
if ($mobile_rewrite = perform) {
rewrite ^ http://m.domain.com redirect;
break;
}
I want something like (pseudo code):
if ($mobile_rewrite = perform && Location != /path/* ) {
rewrite ^ http://m.domain.com redirect;
break;
}
Thank you for your tips!
I actually found something using the $request var:
set $mobile_rewrite = [...] (perform or do_not_perferm)
if ($request ~* "path") {
set $mobile_rewrite do_not_perform;
}
if ($mobile_rewrite = perform) {
rewrite ^ http://m.domain.com redirect;
break;
}
Maybe not the best solution, but it works!
if ($request_uri !~ "^/blog/\w+$")
{
set $mobile_rewrite do_not_perform;
}
and i think this work.
Related
i try to config nginx with tonic rest for multiple sites on my mac.
My nginx runs as localhost on my mac.
My root is /Users/thorsten/Sites
In root i habe some projects e.g. /project1, /project2
Each project has the tonic rest folder /standard/rest...
In nginx.conf i try
location /rest/ {
fastcgi_pass_header Authorization; # Pass the http authorization parameter to the PHP script
if (!-e $request_filename) {
rewrite ^/(.*)$ /rest/dispatch.php?/$1 last;
break;
}
}
Nothing happend.
Do i need a config for each project or can i have a global config for all project e.g. $project/rest/...?
This config works for me
location ~ ^/(?<project>.+)/standard/rest/ {
fastcgi_pass_header Authorization;
include /usr/local/etc/nginx/conf.d/php-fpm;
if (!-e $request_filename) {
rewrite ^/(.*)$ /$project/standard/rest/dispatch.php?/$1 last;
break;
}
}
How do I redirect example.com/url to www.example.com/url using HipHop VM. I'm not sure where to begin with since the rewriterules section seems to only apply pattern matching to the path
I've tried
RewriteRules {
rootdomain {
pattern = *
to = http://www.example.com
qsa = false
redirect = 301
conditions {
* {
pattern = ^example.com$
type = host
negate = false
}
}
}
}
I currently have a image being outputted by server side PHP at a url like this:
domain.com/m/image.jpg
I'd like to have this image viewable at the url:
i.domain.com/image.jpg
Is this possible in the nginx conf?
Note: I currently have my "i" subdomain remapped to a /images/ folder.
Also I'm currently serving static images like the following:
http://i.domain.com/simage.jpg (thumb)
http://i.domain.com/image.jpg (medium)
http://i.domain.com/oimage.jpg (full quality)
Here's my domain.conf file: http://pastebin.com/BBWUJFxu
Also within nginx.conf I have this for the subdomain currently:
#setup subdomain i.domain.com
server {
server_name i.domain.com;
access_log /var/log/nginx/i.domain.com.access.log;
error_log /var/log/nginx/i.domain.com.error.log;
root /var/www/domain.com/html/images;
index index.php index.html index.htm;
location / {
#change this to a 404 img file .jpg
try_files $uri $uri/ /notfound.jpg;
rewrite "/s([A-Za-z0-9.]+)?" /small/$1 break;
rewrite "/o([A-Za-z0-9.]+)?" /orig/$1 break;
rewrite "/([A-Za-z0-9.]+)?" /medium/$1 break;
}
location = / {
rewrite ^ http://domain.com permanent;
}
}
The third rewrite is the one I'm looking to replace with my non static served image file, any idea how to go about this?
Update 2:
Ok, so the actual files are in /images/size/image.jpg and not actually /m/, /m/ is just a psuedo directory.
Given that, I think it should be as simple as:
server {
server_name i.domain.com;
access_log /var/log/nginx/i.domain.com.access.log;
error_log /var/log/nginx/i.domain.com.error.log;
root /var/www/domain.com/html/images;
location / {
rewrite /s([A-Za-z0-9.]+)? /small/$1 break;
rewrite /o([A-Za-z0-9.]+)? /orig/$1 break;
rewrite /([A-Za-z0-9.]+)? /medium/$1 break;
#change this to a 404 img file .jpg
try_files $uri $uri/ /notfound.jpg;
}
location = / {
rewrite ^ http://domain.com permanent;
}
}
But not 100% sure on it. Give that a shot and see. I moved the try below, as it was trying the files, which did not exist, first and then erroring out.
UPDATE
Since you are trying to just pass it through to a script, we need to capture that and pass it through to the script. I changed the root, since you are doing a "psuedo" images directory and we will need access to the image processing script.
Ok, since there is no PHP script in the middle (mis-read on my part) then the below should do what you want it to.
#setup subdomain i.domain.com
server {
server_name i.domain.com;
access_log /var/log/nginx/i.domain.com.access.log;
error_log /var/log/nginx/i.domain.com.error.log;
root /var/www/domain.com/html;
location ~* \.jpg { # add more extensions if you need to
#change this to a 404 img file .jpg
try_files $uri $uri/ /m/$uri /m/notfound.jpg;
#get the main part working first
#rewrite "/s([A-Za-z0-9.]+)?" /small/$1 break;
#rewrite "/o([A-Za-z0-9.]+)?" /orig/$1 break;
#rewrite "/([A-Za-z0-9.]+)?" /medium/$1 break;
}
location = / {
rewrite ^ http://domain.com permanent;
}
}
If that works, I am not sure how to go about doing the rewrites for the small / orig / medium (as I am not sure about the logic needed), but hopefully you can get it working.
In your domain conf, you just need to add a location for /m
location /m {
rewrite ^/m/(.*)$ http://i.domain.com/$1 permanent;
}
Should do it, pending any minor mistakes.
I need to do a rewrite with nginx from /blah/.../3275 to /id/3275 if the second file exists, otherwise I want to hand it off to apache. Here is my (feeble) attempt
(...) represents irrelevant stuff
if ($request_filename ~^/.../([0-9]+)/$) {
if (-d /id/$1) {
rewrite ^/.../[0-9]+/([0-9]+)/$ /id/$1;
}
}
Does anyone have any ideas
Best to do this with internal rewrites:
set $original_uri $uri;
location /blah/irrelevant_stuff {
error_page 404 = #apache;
rewrite ^/blah/irrelevant_stuff/([0-9]+)$ /id/$1;
}
location #apache {
proxy_pass http://upstream$original_uri;
}
The above answer from wulong I couldn't get to work for some reason but I did get it to work by using
if (!-e $request_filename) {
proxy_pass http://apache$original_uri;
break;
}
rather than the error_page directive. Same idea basically
I would like to restrict access to my /admin URL to internal IP addresses only. Anyone on the open Internet should not be able to login to my web site. Since I'm using Lighttpd my first thought was to use mod_rewrite to redirect any outside request for the /admin URL back to my home page, but I don't know much about Lighty and the docs don't say much about detecting a 192.168.0.0 IP range.
Try this:
$HTTP["remoteip"] == "192.168.0.0/16" {
/* your rules here */
}
Example from the docs:
# deny the access to www.example.org to all user which
# are not in the 10.0.0.0/8 network
$HTTP["host"] == "www.example.org" {
$HTTP["remoteip"] != "10.0.0.0/8" {
url.access-deny = ( "" )
}
}
This worked for me:
$HTTP["remoteip"] != "192.168.1.1/254" {
$HTTP["url"] =~ "^/intranet/" {
url.access-deny = ( "" )
}
}
!= worked over ==.