Nginx document root

Hello,

I am new to FreeBSD and try to get nginx running. So far I have done a fresh installation and did follow the tutorial on:
http://bin63.com/how-to-install-nginx-and-php-fpm-on-freebsd

It was not a big problem, to get this basic configuration running.
Here comes the but. :)

My /usr/local/etc/nginx/nginx.conf
Code:
user www;
worker_processes 4;
error_log /var/log/nginx/error.log;
pid /var/run/nginx.pid;
events {
    worker_connections 1024;
}
http {
#    geoip_country /opt/conf/GeoIP.dat;
    include /usr/local/etc/nginx/mime.types;
    default_type application/octet-stream;
    access_log off;
    server_tokens off;
    sendfile on;
    client_max_body_size 200m;
    client_body_buffer_size 1m;
    keepalive_timeout 1;
    port_in_redirect off;
    #gzip on;
    #gzip_http_version 1.1;
    #gzip_vary on;
    #gzip_comp_level 6;
    #gzip_proxied any;
    #gzip_types text/plain text/css application/json application/x-javascript application/xml application/xml+rss text/javascript;
    #gzip_buffers 16 8k;
    #gzip_disable "MSIE [1-6].(?!.*SV1)";
    include /usr/local/etc/nginx/conf.d/*.conf;
}
Compression and GeoIP I don't need at this point.

My /usr/local/etc/nginx/conf.d/default.conf
Code:
server {
        listen 80;
        server_name freebsd;
        #rewrite ^ http://_$request_uri?;
}
server {
        listen 80;
        server_name freebsd;
        server_name_in_redirect off;
        location ~* ^.+\.(ico|js|gif|jpg|jpeg|png|bmp)$ {
          root /var/www/default;
          expires 30d;
        }
        location / {
            root /var/www/default;
            index index.html index.htm index.php;
        }
        location ~ \.php$ {
            root /var/www/default;
            fastcgi_pass 127.0.0.1:9000;
            fastcgi_index index.php;
         #   fastcgi_param GEOIP_COUNTRY_CODE $geoip_country_code;
         #   fastcgi_param GEOIP_COUNTRY_NAME $geoip_country_name;
            fastcgi_param SCRIPT_FILENAME /var/www/default/$fastcgi_script_name;
            include fastcgi_params;
        }
        location ~ /\.ht {
            deny all;
        }
}

When I try to visit the page I get "404 File not found" and in the error.log for nginx I have:
Code:
2012/11/10 12:23:05 [error] 1268#0: *6 "/usr/local/etc/nginx/html/index.html" is not found (2: No such file or directory), client: 192.168.0.100, server: freebsd, request: "GET / HTTP/1.1", host: "192.168.0.103"

Why the server looks for the index.html at /usr/local/etc/nginx/html/ and where can I change that?
Of course when I create a symbolic link to /var/www/default/ I see in the browser the correct page.

Thanks a lot in advance.

Cheers
comalcon
 
Hello,

I was able to solve that issue.
According to http://wiki.nginx.org/Pitfalls#Root_inside_Location_Block having root in the location section is not a good practice, so I moved them out there, my default.conf looks now like that and it works fine now.
Code:
server {
        listen 80;
        server_name freebsd;
        server_name_in_redirect off;
        root /var/www/default;
        location ~* ^.+\.(ico|js|gif|jpg|jpeg|png|bmp)$ {
          root /var/www/default;
          expires 30d;
        }
        location / {
            index index.html index.htm index.php;
        }
        location ~ \.php$ {
            fastcgi_pass 127.0.0.1:9000;
            fastcgi_index index.php;
         #   fastcgi_param GEOIP_COUNTRY_CODE $geoip_country_code;
         #   fastcgi_param GEOIP_COUNTRY_NAME $geoip_country_name;
            fastcgi_param SCRIPT_FILENAME /var/www/default/$fastcgi_script_name;
            include fastcgi_params;
        }
        location ~ /\.ht {
            deny all;
        }
}

Thanks a lot
Cheers :)
 
Back
Top