nginx conf for tonic rest with multiple sites on mac - macos

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;
}
}

Related

Nginx Joomla Internationalization URL rewriting

I'm using Joomla in combination with Nginx, and I'm currently trying to achieve some URL rewriting for a website that has several langages supported (italian, french, chinese, and deutch)
The urls have the country code after the domain name, like so :
http://www.example.com/fr/test/test.html
or
http://www.example.com/de/test/test.html
I'm looking to rewrite the urls so the country code is part of the subdomain :
so
http://www.example.com/fr/test/test.html
becomes
http://fr.example.com/test/test.html
Is there a way to achieve this with Nginx or should I look into a third party extension for Joomla (not my favorite choice).
Thanks !!
Update :
I wasn't clear enough : I wanted the redirection from the rewrited URL to be transparent. Here is what I came up with, thanks to VBart help :
server {
server_name ~^(?<lang>.+)\.example\.com$;
location / {
rewrite /(.*)$ /$lang/$1 break;
proxy_pass http://www.example.com;
proxy_redirect http://www.example.com http://$lang.example.com/$request_uri;
}
}
Now, is there a way for Nginx to modify links on the fly in the served content ? ie: I want all the link in the generated page to look like http://fr... instead of http://.../fr/... ?
server {
server_name ~^(?<lang>.+)\.example\.com$;
...
}
server {
server_name www.example.com;
rewrite ^/(?<lang>[a-z]+)(?<rest>.+)$ http://$lang.example.com$rest? permanent;
}
opposite example:
server {
server_name ~^(?<lang>.+)\.example\.com$;
return 301 http://www.example.com/$lang$request_uri;
}
server {
server_name www.example.com;
...
}

nginx magic sub domains - help for yoda needed

I am planning to offer some free hosting for ruby development. At the moment I have to manually edit nginx to add sub domains when a user is create to point to his directory /home/$user/www/public
so for user yoda I have something like this
server {
listen 80;
server_name yoda.jedi.am;
root /home/yoda/www/public;
passenger_enabled on;
}
Now suppose I add user obione is there anyway to set nginx to automatically server user.jedi.am with root /home/user/www/public and if that is not available to redirect to the main root ?
Thanks
Try something more like:
server {
listen 80;
server_name ~^(.*)\.jedi\.am$
if ($hostname ~ ^(.*)\.jedi\.am$) {
set $user $1;
}
if ( ! -d /home/$user/www/public ) {
rewrite . http://jedi.am/ redirect;
}
root /home/$user/www/public;
passenger_enabled on;
}
Untested, but this or something like it should work.

Rewrite url to sub domain in NGINX

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.

nginx rewrite rules

I'm trying to implement nginx rewrite rules for the following situtation :
- Request /testfa/styles/style.css should be redirected to /testfa/templates/styles/style.css
I've enabled rewrite logging for my server, created following rules:
location /testfa {
rewrite ^/styles/(.+)?$ /testfa/templates/styles/$1 last;
}
but when I'm trying to perform request, I'm getting 404 error from server, and log file doesn't contain any info about rewriting, only following message:
open() "......../testfa/styles/style.css" failed (2: No such file or directory)
What is the correct way to perform such a rewrite for nginx ?
location /testfa/ {
rewrite ^/testfa/styles/(.+)$ /testfa/templates/styles/$1 last;
}
does this work for you ?
my tested virtual >
server {
listen ...ip...:80;
server_name sub.domain.com;
root /usr/local/www/test;
error_log /usr/local/www/test/error_debug.log debug;
rewrite_log on;
location /testfa/ {
rewrite ^/testfa/styles/(.+)$ /testfa/templates/styles/$1 last;
}
}
this works. even log has reported :
2011/11/25 01:06:52 [notice] 35208#0: *456705 rewritten data: "/testfa/templates/styles/test.css", args: "", client: IP, server: sub.domain.com, request: "GET /testfa/styles/test.css HTTP/1.1", host: "sub.domain.com"

nginx rewrite question

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

Resources