Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

I am trying to have a subdirectory for a virtual host.. so say xxx.xxx.xxx/vhost1 and xxx.xxx.xxx/vhost2. I have the following config file:

user www-data;
worker_processes  4;

error_log  /var/log/nginx/error.log;
pid        /var/run/nginx.pid;

events {
    worker_connections  1024;
    # multi_accept on;
}

http {
    include       /etc/nginx/mime.types;

    access_log  /var/log/nginx/access.log;

    sendfile        on;
    #tcp_nopush     on;

    #keepalive_timeout  0;
    keepalive_timeout  65;
    tcp_nodelay        on;

    gzip  on;
    gzip_disable "MSIE [1-6]\.(?!.*SV1)";

    include /etc/nginx/conf.d/*.conf;
    include /etc/nginx/sites-enabled/*;

    server {
        listen   80 default;

        access_log  /var/log/nginx/localhost.access.log;

        location / {
                root   /var/www/nginx-default;
                index  index.html index.htm;
        }

        location /adminapi {
                if (-f $request_filename) {
                        break;
                }

                rewrite  ^/(.*)$  /index.php?$1  last;
                root   /var/www/api/src/frapi/admin/public;
                index  index.php;
        }

        location /api {
                 if (-f $request_filename) {
                        break;
                 }

                rewrite  ^/(.*)$  /index.php?$1  last;
                root   /var/www/api/src/frapi/admin/public;
                index  index.php;
        }

        location /phpmyadmin {
                 root   /usr/share/phpmyadmin;
                 index  index.php;

                 fastcgi_pass 127.0.0.1:9000;
                 fastcgi_param SCRIPT_FILENAME /usr/share/phpmyadmin/index.php;
                 include /etc/nginx/fastcgi_params;
                 fastcgi_param SCRIPT_NAME /index.php;
        }

        location /doc {
                root   /usr/share;
                autoindex on;
                allow 127.0.0.1;
                deny all;
        }

        location /images {
                root   /usr/share;
                autoindex on;
        }

        #error_page  404  /404.html;

        # redirect server error pages to the static page /50x.html
        #
        #error_page   500 502 503 504  /50x.html;
        #location = /50x.html {
        #       root   /var/www/nginx-default;
        #}

        # proxy the PHP scripts to Apache listening on 127.0.0.1:80
        #
        #location ~ \.php$ {
                #proxy_pass   http://127.0.0.1;
        #}

        # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
        #
        location ~ \.php$ {
                fastcgi_pass   127.0.0.1:9000;
                fastcgi_index  index.php;
                fastcgi_param  SCRIPT_FILENAME  /var/www/nginx-default$fastcgi_script_name;
                include fastcgi_params;
        }

        # deny access to .htaccess files, if Apache's document root
        # concurs with nginx's one
        #
        location ~ /\.ht {
                deny  all;
        }
}


}

the xxx.xxx.xxx/phpmyadmin works, but the layout is wrong.. I am guessing that it can't find the css and images... what do I need to change?

the other xxx.xxx.xxx/vhost does not work at all

share|improve this question

1 Answer 1

For your phpmyadmin not finding its CSS, you should be able to diagnose that either by using a client-side tool like Firebug or Chrome Developer Tools to see what requests are failing and what URIs they are requesting, or by tailing /var/log/nginx/access.log and /var/log/nginx/error.log to see the same information from the server side.

For your other question about nginx not displaying http://sample.com/vhost1 etc, your root directory is configured to read from /var/www/nginx-default. So you should have a directory at /var/www/nginx-default/vhost1 with a file named index.html or index.htm. Or if you'd like the URI /vhost1 to point to a different filesystem location, simply add another block to your configuration file, eg:

location /vhost1 {
    root   /home/sample/www/vhost1;
    index  index.html;
}

location /vhost2 {
    root   /var/www/vhost2;
    index  index.html;
}
share|improve this answer
    
if you see in my code above vhost1 = admin api and I did have a location /adminapi there.. but still I cant navigate there –  EquinoX Mar 4 '11 at 16:23
    
the url to the css and image are at xxx.xxx.xxx.xxx/./themes/original/img, where as this is not true.. I am not sure what . is here... –  EquinoX Mar 4 '11 at 16:41

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.