Posted by luxpir on September 10, 2013 at 2:51pm
In D7 (upgraded from D6) I have managed to get clean URLs working with Nginx thanks to the various help and documentation available here and there online.
What doesn't work are queries of the ?page=1
or ?destination=
type, for some reason.
The config is very similar to: http://docs.ngx.cc/en/latest/topics/apps/drupal.html, particulary the line:
location @rewrite {
rewrite ^/(.*)$ /index.php?q=$1;
and the few preceding lines.
In effect this means that the pagers and overlays are broken, and other queries I haven't come across yet.
Anyone got a fix for this in mind?
Comments
Try somesing like
Try somesing like this:
location / {
try_files $uri $uri/ @drupal;
}
That is not recomendet:
location @rewrite {
rewrite ^/(.*)$ /index.php?q=$1;
Thanks - already in place
Above the @rewrite lines is the following, already in place:
location / {
try_files $uri $uri/ @rewrite;
}
So, with no '@drupal' section in the vhosts file, what would @drupal refer to if I used it?
(Thanks)
EDIT:
I changed the @rewrite reference to @drupal, in case the @rewrite call was causing the problem. Doesn't seem to make a difference?
You need to update the config
The config you referenced is old, slow and not very secure.
Thanks Perusio
Thanks for the advice. I am not using that config specifically. I have more security features in place on the config I have (/backup, settings.php, code files etc. all denied)
I know your own config is very secure, but I wanted something simple and easy to maintain for a low-level sysadmin (me!). I see in your config you use Lua to solve the query problem. Is there no other way?
So far it works great for clean URLs, but I'm stuck on this query issue. Can you comment on the rewrite line in particular? I'll repaste the relevant section here:
location / {
try_files $uri $uri/ @rewrite;
#try_files $uri $uri/ /index.php?$args @rewrite;
#try_files $uri $uri/ /index.php?q=$uri&$query_string @rewrite;
}
location @rewrite {
# Some modules enforce no slash (/) at the end of the URL
# Else this rewrite block wouldn't be needed (GlobalRedirect)
#rewrite ^(.)$ /?q=$1&$args last;
#rewrite ^/(.)$ /index.php?q=$1&$args;
rewrite ^/(.)$ /index.php?q=$1;
#rewrite ^/(.)$ /index.php?q=$uri&$query_string;
The #commented out lines are just some tests I've run in the last day, trying to fix this. I'll delete them soon if I can get confirmation that they won't work in some other config.
Stabbing in the dark a bit, as you'll see.
Lua is used when you have URIs that need to be escaped
is that your problem?
Remove the
/$uri
from thetry_files
all requests go through index.php.Perhaps not
Thanks, not sure if this counts as escaping, but I need the overlays in the format
/url/#overlay[...]
and/url/page?=2
to work as planned. I tried your suggestion - top line of try_files is what it was, uncommented line is what I tried. Neither seemed to do the trick yet?location / {
#try_files $uri $uri/ @rewrite;
try_files $uri/ @rewrite; #also tried try_files $uri @rewrite;
}
location @rewrite {
rewrite ^/(.)$ /index.php?q=$1;
}
No luck yet, then. Appreciate any further thoughts. I presume nobody else has this problem with their configs, which makes me wonder what I've done wrong!
Simplify this:
location / {
try_files $uri /index.php?q=$uri&$args;
}
Simplify it to
location / {
try_files $uri /index.php?q=$uri&$args;
}
Tried, failed; thanks
Still not sure what's happening. I ran debug on Nginx while accessing:
/blog?page=1
And here is the result: http://pastebin.com/XiEc3Wkd (fun starts on line 65, I think)
The full vhost config is here: http://pastebin.com/h97tHfyE
Nothing to see there
you stopped the paste too soon. Let it go until the end, i.e., returning something as reponse.
Updated log link
Here's the rest of that section of the log: http://pastebin.com/HN00T2jm
Paste your FastCGI config
It seems something could be fishy there.
This config?
fastcgi_params: http://pastebin.com/cDuJRaB8
In the course of testing things I added line two, now commented out. Nothing else changed.
New information: getting the following error
Notice: Undefined variable: base_path in eval() (line 3 of /usr/share/nginx/www/modules/php/php.module(80) : eval()'d code).
in Watchdog and Ajax not working in Views preview. Throwing a 500/internal server error. Could all be related to the same issue - how PHP is handled?
Definitely
something is wrong in the PHP handling of your config, hence the 500.
Suggestion: Try my config and see how it goes. Start simple.
Hello,Are you trying with
Hello,
Are you trying with this:
In your nginx.conf, add fastcgi.conf with the content:
In your server name config, check my reference:
Please note along SCRIPT_FILENAME we having $document_root, some document I was seen /scripts instead of $document_root.
Thanks folks - fixed
Appreciate the help, folks. I bit the bullet in the end and switched over to Perusio's config. It has taken me a while to get my head around the dependencies and the settings, but not half as long as it was taking to write my own 'simple' config.
Now the admin overlays and pagers are working as planned (half think it was in my fastcgi_params that I was missing something) and I'm back underway with development.
The next hurdle will be implementing ssl certs, but hopefully that won't be such a change as the Perusio config obviously is already set up to handle these.
So again, many thanks, and hope to be able to be of as much use to you or others one of these days.
?destination=node showing error page
Hi Luxpir
I am also facing the issue mentioned in subject line.
I have configured recently nginx with drupal project,
home page is coming but when i go for login then the above URL is coming with error page. I tried configuring as suggested in post but might be i am missing something which Perusio's config suggested and you have used.
please provide some help / text to put in config file.
few lines of my config file is :
location / {
root html;
index index.php index.htm index.html;
try_files $uri $uri/ @rewrite;
expires max;
}
location @rewrite {
if (!-e $request_filename) {
rewrite ^/(.*)$ /index.php?q=$1 last;
break;
}
Seeking a quick help here.
Thanks,
Naresh K.
Working config in response to original poster.
This is one of those questions that didn't have an answer posted.
Specifically, as of 12/29/2014, http://wiki.nginx.org/Drupal ...has the following rewrite:
As you can see, the above also works for overlays because it try_files $uri first, and then rewrites using, "rewrite ^ /index.php;", in which case, then it will go to the last php location.
I haven't tried perusio's nginx configuration in its entirety that's in github but I've been modifying various parts of it to make it easier to understand, and to improve on it.
It appears that he uses https://raw.githubusercontent.com/perusio/drupal-with-nginx/D7/apps/drup... ...to redirect to the hardcoded fastcgi parameters instead of having a rewrite location mentioned above.
You should use http://tools.pingdom.com/fpt/ and/or locally installed tools to verify that the changes do make for improvements.
great
This solution work for me!
Ivan Mejia
www.medioyforma.info
www.drupalmexico.com
same issue, wnmp web server
worker_processes 1;
error_log logs/error.log;
pid logs/nginx.pid;
events {
# Max value 16384
worker_connections 8192;
# Accept multiple connections
multi_accept on;
}
Settings that affect all server blocks
http {
include php_processes.conf;
include mime.types;
default_type application/octet-stream;
Begin HTTP Server
server {
listen 80; # IPv4
server_name localhost;
}
}
End HTTP Server
Begin HTTPS Server
server {
listen 443 http2 ssl;
server_name localhost;
ssl_certificate cert.pem;
ssl_certificate_key key.pem;
ssl_session_cache shared:SSL:10m;
ssl_session_timeout 10m;
}
} # End HTTPS Server
}