Portal Home > Knowledgebase > Articles Database > nginx quirk on running encrypted script? (running with php-fpm)


nginx quirk on running encrypted script? (running with php-fpm)




Posted by Darvil, 10-12-2008, 08:32 AM
Well I decided to see if I can run one of the encrypted script on nginx. Everything was ok until I ran into a snag. Now the script is hardcoded to a domain name so if I just type in the IP for example, I would get the error "The encoded file /var/www/html/index.php is not permissioned for this server" Now if I type in the domain name, its not an issue (site loads up fine); at least on apache it isn't. Now after I got nginx started and verify that php is working with it, I got the error I mentioned above. Now using the domain name, I shouldn't be getting the error but I still do. I'm hoping someone here can give me some tips or ideas on what might be happening. I did enter the domain name in the server_name entry and everything else is pretty much the standard nginx config. Would it be somehow related to the way php is running (php-fpm) compared to the DSO method of apache? Somehow the script is not seeing that I am trying to access from an actual domain. Its probably something really simple.

Posted by Boris A Dolgov, 10-12-2008, 09:40 AM
Have you done include fastcgi_params; in location, handling your php files? You may contact me, I can help you to fix this issue.

Posted by tajidyakub, 10-12-2008, 09:51 AM
It is possible because of the fast-cgi / php-fpm, since the php request will come from 127.0.0.1 and not directly, cmiiw, I don't know if there is a way around this issue..

Posted by Darvil, 10-12-2008, 12:59 PM
location ~ \.php$ { # root html; fastcgi_pass 127.0.0.1:9000; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME /var/www/html$fastcgi_script_name; # include fastcgi_params; Hi there. As you can see I've commented out the "include" I am not sure what I'm suppose to put there for it? Also I tried some random stuff that sorta came close. For example I created a folder that is the actual domain name and put it in the / directory. And then in the fastcgi_param line I tried /domain_name$fastcgi_script_name; Unfortunately now the error shows up as I don't have permission for "/domain_name". If I can't get away with not including a "/" I could probably get it to work.

Posted by Boris A Dolgov, 10-12-2008, 01:28 PM
Try the following configuration:/var/www/html should be 755.

Posted by Darvil, 10-12-2008, 01:54 PM
Boris It works! Thanks. Now I run into another snag with getting all my rewrite in .htaccess to work. I have converted all of them Here are 2 of them for example rewrite ^signup/$ index.php?view=signup last; rewrite ^login/?([^\/].*)?$ index.php?view=login$1 last; I suppose I can't have them be in a .htaccess in the /var/www/html folder Where exactly in the config file am I suppose to put these rules? There are about 40 of them but they are all similar to those above 2 lines. Thanks for the help!

Posted by Boris A Dolgov, 10-12-2008, 01:57 PM
Put them into "server" context. Also, I think, you must replace "^" to "^/", because nginx parses request_uri, and it always start with "/"

Posted by Darvil, 10-12-2008, 02:36 PM
Boris. I still am having issues. For example I've redone the rewrite with your tip. rewrite ^/signup/$ index.php?view=signup last; rewrite ^/login/?([^/\/].*)?$ index.php?view=login$1 last; rewrite ^/logout/$ index.php?view=logout last; including the middle [^/\/].*)?$ Now when I try to logout I get the "No input file specified." I ran into this problem before and it was because I didn't set the fastcgi_param. But now that its all fixed do I need to somehow append something to the rewrite? Thanks for the help!

Posted by Boris A Dolgov, 10-12-2008, 03:00 PM
1. No, let the middle [^/\/].*)?$ as it was 2. Try adding "/" before "index.php" too: rewrite ^/signup/$ /index.php?view=signup last; rewrite ^/login/?([^\/].*)?$ /index.php?view=login$1 last; rewrite ^/logout/$ /index.php?view=logout last;

Posted by Darvil, 10-12-2008, 03:21 PM
Boris Thanks! It works. I've also changed all the other necessary links (other then index.php) and now I also see my mistake. BUT I ran into another snag. I mention to you that I do have ALOT of rewrites to copy and paste. It turns out to be more then 40 rewrites. After I copy and pasted all of the rewrites in, I get this error [emerg] 5874#0: invalid number of arguments in "rewrite" directive in /usr/local/nginx/conf/nginx.conf:285 Does nginx have some limits on the amount of rewrites you can do in the server context? If so how can I overcome it? Thanks again! I'm so close.

Posted by Boris A Dolgov, 10-12-2008, 03:26 PM
No, nginx has no limits :-) "Invalid number of arguments" error means, that there are more than two arguments to the rewrite directrive. Look, are there any spaces in rewrite conditions or in rewrite result on line 285?

Posted by Darvil, 10-12-2008, 04:17 PM
Boris. I'm sorry I wasted your time. Actually it was a silly mistake. I missed one (that line) as it wasn't last; but rather the old htaccess format. My bad. Now I hit another snag. I'm actually running a youtube clone and it seems the videos are not loading up anymore. I did compile nginx with the flv ability but I don't think its actually necessary and I don't think that is actually causing this problem. Any idea?

Posted by ub3r, 10-12-2008, 07:47 PM
Is your embeded video code being output correctly? Boris, Good to have you around!

Posted by Darvil, 10-12-2008, 07:57 PM
ub3r Its a youtube clone and the videos are working (when I turn apache back on). Where as under nginx it is not working for some reason. I've contacted the coder of the flv player of the script. I can't believe I would run into a thing like this right at the end of the tunnel (and I could see the light ahead). Boris has been a great help! Even if I can't get the video site to work (which would be sad), I can use what I learned today to switch some of my other sites (big forum) etc to nginx. Thanks again Boris.

Posted by Darvil, 10-12-2008, 08:00 PM
The developer just sent me a message. Turns out to be something you nginx nerds might be able to help me with. This is his question. Does nginx not allow the shorthand PHP tags? This seems to be what is causing the problem: http://video.sarnworld.com/flv_playe...erConfig/7.xml

Posted by Darvil, 10-12-2008, 08:26 PM
GOT it!! short_open_tag was off in my php.ini turned it on and that fixed it. Thanks to #nginx on irc. Man I really love how people came around to help. Feels great to have it all up and running. Thanks again everyone and especially Boris.

Posted by Boris A Dolgov, 10-12-2008, 11:13 PM
oh, you've posted the solution before me And I want to tell something about flv: flv format is that when browser wants to get a file from definite position, it doesn't operate with http headers but calls xxx.flv?start=position. It's very easy to enable flv streaming - just add location ~ \.flv$ {flv on; } to your configuration (of course, if flv-streaming is not provided by php-script, but I don't recommend this on high loads). Last edited by Boris A Dolgov; 10-12-2008 at 11:18 PM.

Posted by Darvil, 10-13-2008, 03:00 AM
Boris If you don't mind me asking. What I see on the internet is And lets say if the flv files are in /var/www/html/files how do you enable it? And would most flash player automatically support the forwarding of the flv file? This actually will seriously come in handy if its true because my site will be hosting alot of LONG video (an hour) clips and waiting for the entire thing to load takes a while and wastes bandwidth. Thanks again.

Posted by Darvil, 10-13-2008, 04:01 AM
Boris I used this But the streaming does not allow me to forward ahead. I tried it on both JWplayer and the one that came with the script and no love. Would the php script actually have to call the flv file in a specific way? I see people talking about Header=XXX for example. Found this thread (http://www.ruby-forum.com/topic/156997 Looks like he had the same issue and it looks like he never manage to solve it either. Thanks! Last edited by Darvil; 10-13-2008 at 04:04 AM.

Posted by Boris A Dolgov, 10-13-2008, 07:44 AM
1) Not "~ .flv" but "~ \.flv" 2) Where are your flv files? And what are their URLs? If they are located in /var/www/html/files, and you access them with http://yoursite/files, then If you specified "root" directive on the "server" context, you don't need to specify it in "location" context. So, just "location ~ \.php {flv; }"

Posted by Darvil, 10-13-2008, 06:16 PM
Thanks Boris! That clarified it for me. Unfortunately the flash player I'm using doesn't support flv seek streaming yet but will in the next version. Its good that at least I can enable it anytime for that function. Lets see how nginx perform for me.



Was this answer helpful?

Add to Favourites Add to Favourites    Print this Article Print this Article

Also Read
WestNIC Reseller Hosting (Views: 3972)
website Monitoring (Views: 413)