I have two problems with Nginx I am hoping someone could help me with.
I have setup an aliased directory in my site called /wordpress/ and made it point to a file outside of my webroot now that’s all working fine and dandy until I try and browse the parent directory: /wordpress. It seems to want to redirect to *.x.co.uk (where x represents my domain name). Config to follow.
My other problem is that my Auth is not covering more than the root directory / despite being in the / caluse to catch anything that’s not /wordpress/ which is confusing me again. So I have to auth if I go to / but if I go /video I can get into my site without auth at all.
I am a bit new to Nginx so it’s prolly something stupid that I got confused on while reading the Wiki.
Anyone have any ideas? Here is my config for your viewing pleasure:
server {
listen 80;
server_name _;
root /server_ws/the_stage/htdocs;
access_log /var/log/nginx/access.log;
error_log /var/log/nginx/error.log;
error_page 404 /error/notfound;
location /wordpress/ {
alias /server_ws/wordpress/;
# try_files $uri $uri/;
}
location ~* ^/wordpress/(.+).(jpg|jpeg|gif|css|png|js|ico|xml)$ {
alias /server_ws/wordpress/$1.$2;
access_log off;
expires 30d;
}
location / {
auth_basic "Restricted";
auth_basic_user_file /etc/apache2/passwords;
index index.php;
if ($host = 'x.co.uk') {
rewrite ^/(.*)$ http://www.x.co.uk/$1 permanent;
}
if (-f $request_filename) {
break;
}
if (!-e $request_filename) {
rewrite . /index.php last;
}
try_files $uri $uri/ /index.php;
}
location ~* ^.+.(jpg|jpeg|gif|css|png|js|ico|xml)$ {
root /server_ws/the_stage/htdocs;
access_log off;
expires 30d;
}
}
Here are some log entries for the auth. You can see in this one were a bot tried to access my robots.txt and fails due to auth:
2012/05/20 11:54:10 [error] 12059#0: *2008 no user/password was provided for basic authentication, client: 108.162.215.232, server: _, request: "GET /robots.txt HTTP/1.0", host: "www.x.co.uk"
But then I go to /video on my site and I get no errors but I get an access log of:
xxx.xxx.xxx.xxx - - [20/May/2012:12:51:35 +0000] "GET /video?cat=gaming&sort=upload_date HTTP/1.1" 301 185 "-" "Mozilla/5.0 (compatible; Googlebot/2.1; +http://www.google.com/bot.html)"
Here is the lastest log for /wordpress access:
xxx.xxx.xx.xxx - - [20/May/2012:13:01:08 +0000] "GET /wordpress HTTP/1.1" 301 185 "-" "Opera/9.80 (Windows NT 6.1; WOW64; U; Edition Campaign 21; en) Presto/2.10.229 Version/11.64"
First question solution is changing
location /wordpress/block to that:And please fix www rewrite, instead of if (which is evil) add this block:
And, by the way, delete
listen 80from first server block, it’s implemented by default.UPD:
rewrite➡return.