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 have a Double Quad-Core Centos 6.3 server with 32GB ram.

I have installed nginx for serving static files and as reverse proxy server to apache as the backend. The panel I am using is IspConfig 3.0.5.2.

Everything seemed to have been working fine at the beginning, but recently I have realized that there is something wrong! Nginx is serving from wrong document root. I have crawled across google and nginx fora but I could not find a solution. I have made several modifications / alterations / amendments to the config files and tried to debug thorugh nginx logs but all for no joy!

Below are my config files and excerpts from logs. Please help me sort out.

//FILE /etc/nginx/nginx.conf

# For more information on configuration, see:
#   * Official English Documentation: nginx.  org/en/docs/
#   * Official Russian Documentation: nginx. org/ru/docs/

user              apache nginx;
worker_processes  8;

error_log  /var/log/nginx/error.log warn;
#error_log  /var/log/nginx/error.log  notice;
#error_log  /var/log/nginx/error.log  info;

pid        /var/run/nginx.pid;


events {
    worker_connections  1024;
}


http {
    # allow long server names
    server_names_hash_bucket_size 64;

    include       /etc/nginx/mime.types;
    default_type  application/octet-stream;

    index  index.html index.htm index.php;

    fastcgi_buffers 8 16k;
    fastcgi_buffer_size 32k;

    log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
                      '$status $body_bytes_sent "$http_referer" '
                      '"$http_user_agent" "$http_x_forwarded_for"';

    log_format mukaanyes '$remote_addr - $remote_user [$time_local] '
                  '"$request" $host "$domain" $status  $body_bytes_sent "$http_referer" '
                  '"$http_user_agent" "$http_x_forwarded_for"';

    # access_log /var/log/ispconfig/httpd/$domain/access.log mukaanyes;
    access_log /var/log/nginxaccess.log mukaanyes;
    #access_log  /var/log/nginx/access.log  main;

    sendfile        on;
    tcp_nopush     on;

    server_tokens off;

    #keepalive_timeout  0;
    keepalive_timeout  65;

    #mukaanyes; Make adjustments to gzip module
    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 text/xml application/xml application/xml+rss text/javascript application/javascript text/x$
    gzip_buffers 16 8k;
    gzip_disable "MSIE [1-6]\.(?!.*SV1)";

    # Load config files from the /etc/nginx/conf.d directory
    # The default server is in conf.d/default.conf
    include /etc/nginx/conf.d/*.conf;

}
// END /etc/nginx/nginx.conf

// FILE /etc/nginx/conf.d/default.conf

server {
        listen  80 default;
        #server_name  _;
        server_name ~^(www\.)?(?P<domain>.+)$;
        server_name_in_redirect  off;
        resolver  127.0.0.1;

        root   /var/www/$domain/web;

        location ~* ^.+\.(jpg|jpeg|gif|png|ico|css|zip|tgz|gz|rar|bz2|doc|xls|exe|pdf|ppt|txt|tar|mid|midi|wav|bmp|rtf|js|swf|flv|mp3)$ {
        access_log off;
        expires 30d;
                }

        location / {
                proxy_connect_timeout       600;
                proxy_send_timeout          600;
                proxy_read_timeout          600;
                send_timeout                600;

                #included fcgid.conf instead
                #fastcgi_param SERVER_NAME $domain; #avoid wrong doc_root, formerly was $host

                # proxy_pass http://$host:82;
                proxy_pass http://$domain:82;

                #mukaanyes added proxy_redirect off
                proxy_redirect off;
                proxy_set_header X-Real-IP  $remote_addr;
                proxy_set_header Host $host; #formerly was $host
                proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;

        }
}
// END /etc/nginx/conf.d/default.conf

// FILE /etc/nginx/conf.d/fcgid.conf

#fastcgi.conf
fastcgi_param  GATEWAY_INTERFACE  CGI/1.1;
fastcgi_param  SERVER_SOFTWARE    nginx;
fastcgi_param  QUERY_STRING       $query_string;
fastcgi_param  REQUEST_METHOD     $request_method;
fastcgi_param  CONTENT_TYPE       $content_type;
fastcgi_param  CONTENT_LENGTH     $content_length;
fastcgi_param  SCRIPT_FILENAME    $document_root$fastcgi_script_name;
fastcgi_param  SCRIPT_NAME        $fastcgi_script_name;
fastcgi_param  REQUEST_URI        $request_uri;
fastcgi_param  DOCUMENT_URI       $document_uri;
fastcgi_param  DOCUMENT_ROOT      $document_root;
fastcgi_param  SERVER_PROTOCOL    $server_protocol;
fastcgi_param  REMOTE_ADDR        $remote_addr;
fastcgi_param  REMOTE_PORT        $remote_port;
fastcgi_param  SERVER_ADDR        $server_addr;
fastcgi_param  SERVER_PORT        $server_port;
fastcgi_param  SERVER_NAME        $server_name;
// END /etc/nginx/conf.d/fcgid.conf

Here is an excerpt from the log file with my custom format "mukaanyes"

66.249.73.224 - - [10/Jul/2013:00:18:02 +0100] "GET /ne_demek/hatil HTTP/1.1" www,mankenresimleri,net "mankenresimleri,net" 404 4196 "-" "Mozilla/5.0 (compatib le; Googlebot/2.1; +http://www.google.com/bot.html)" "-"

/ne_demek/hatil is a request to http; // nedir.anlambilim.net, but it is being tried to be served from http; // mankenresimleri.net and returns 404; Same situation is common and reciprocal among other domains on the server.

This mostly happens to Google Bot, iPhone and Android devices as far as i can conclude from logs. I could not reproduce the error on my machine, it is visible from the logs and Google Webmaster Tools Crawl Error Reports.

Please help.

share|improve this question
    
Is that your only server block? It is quite bizarre. Exactly how and why did you set it up that way? –  Michael Hampton Jul 28 '13 at 19:06
    
Like Michael say, if you dont whant problems try to do one vhost per domain or one server block per each domain But in the nginx docs are some diferents ways to define the server_name: nginx.org/en/docs/http/server_names.html –  Skamasle Jul 28 '13 at 20:33
    
I had no problems having only one server block, I define server_name with preg capture. That does not seem to make problems. As to why I do not have separate vhost files for each domain is I could not be able to run nginx plugin with IspConfig, and I cant make vhost files manually each time they are created/edited. Some of the sites where fcgid at first and I suspect it be the culprit and included fcgid.conf then changed the vhost to use mod_php. Besides, this ONLY seem to happen to BOTs and Mobile Users, No PC user can reproduce the problem. What do you think the problem is? –  M Kaan Ye┼čilyurt Jul 29 '13 at 0:44

Your Answer

 
discard

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

Browse other questions tagged or ask your own question.