Welcome! Log In Create A New Profile

Advanced

Set Environment variable

Posted by MySchizoBuddy 
Set Environment variable
September 14, 2009 04:22PM
In Apache I can set an environment variable using SetEnv
For E.g
[code]
<VirtualHost *:80>
DocumentRoot /var/apache2/htdocs/tutorial/Web/
ServerName dev.tutorial.local
SetEnv FLOW3_CONTEXT Development
</VirtualHost>
[/code]

Whats the equivalent way to do it in Nginx

Second whats the correct rewrite rule for this simple one
[code]
# Continue only if the file/symlink/directory does not exist
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-l
RewriteRule (.*) index.php/$1
[/code]

I'm trying this code but i'm getting "rewrite or internal redirection cycle while processing"
[code]
if (!-e $request_filename) {
rewrite ^/(.*)$ /index.php/$1 last;
break;
}
[/code]



Edited 1 time(s). Last edit at 09/14/2009 04:26PM by MySchizoBuddy.
Re: Set Environment variable
September 15, 2009 12:06AM
"SetEnv FLOW3_CONTEXT Development" is a PHP directive not an nginx directive. Not sure how to pass it but perhaps in php.ini? How are you running PHP?

For the rewrite you can use:

[code]
if (!-e $request_filename) {
rewrite ^/(.*)$ /index.php/$1 last;
}
[/code]

May or may not need "$" after (.*), can try both ways.

But more efficient way, if you are using a recent version of nginx is to use "try_files":

Try:

[code]
try_files $uri $uri/ index.php/$uri index.php;
[/code]

If there are arguments (like "?id=xyz") then you may need to change "index.php/$uri" to "index.php/$uri&$args" - assuming there is an ampersand between the URI and the arguments.

--
Jim Ohlstein
Re: Set Environment variable
September 15, 2009 04:04AM
whats the way to set environment or server variables from nginx. i have read somewhere about an ENV directive. although it isn't in the documentation

Can you link to documentation about try_files

Thank you for you help. I appreciate it
Re: Set Environment variable
September 15, 2009 08:57AM
http://wiki.nginx.org/NginxCoreModule#try_files

--
Jim Ohlstein
Sorry, only registered users may post in this forum.

Click here to login

Online Users

Guests: 238
Record Number of Users: 8 on April 13, 2023
Record Number of Guests: 500 on July 15, 2024
Powered by nginx      Powered by FreeBSD      PHP Powered      Powered by MariaDB      ipv6 ready