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

I've been trying to setup a Sugar CRM instance. I've got a domain that has its main site on a server (www.domain.com) and I've created a subdomain (sugar.domain.com), but I wnat this subdomain to be hosted on another server.

This second server has nginx installed, and there's a working WordPress blog there on a virtualhost, so I would need to setup a second site. To do this I've created the directory structure, and I've created a /etc/nginx/sites-enabled/sugar.domain.com configuration file that has the following:

*

    server {
                  listen   80;
                  server_name sugar.domain.com *.domain.com;
                  access_log  /var/www/sugar/log/access.log;
                  error_log      /var/www/sugar/log/error.log info;
                  location / {
                      root /var/www/sugar;
                      index index.php;
                  }

    location ~ .php$ {
        fastcgi_split_path_info ^(.+\.php)(.*)$;
        fastcgi_pass   backend;
        fastcgi_index  index.php;
        fastcgi_param  SCRIPT_FILENAME  /var/www/sugar/$fastcgi_script_name;
        include fastcgi_params;
        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_intercept_errors        on;
        fastcgi_ignore_client_abort     on;
        fastcgi_read_timeout 180;

    }


    ## Disable viewing .htaccess & .htpassword
    location ~ /\.ht {
        deny  all;
    }
}
upstream backend {
              server 127.0.0.1:9000;

}

As far as I know, I need the *.domain.com parameter on the "server_name" flag, but something is crashing here: I get either a 403 Forbidden error, or I get PHP code (I can read the PHP file code in the browser, like normal text) that somehow is not executed. I've tried setting permissions to 755 inside the /var/www/sugar/ directory, and I've also set up the owner:group with a chown -R www-data:www-data /var/www/sugar/

The thing is, I don't now if my mistake is in the nginx site configuration, in my folder permissions, or in other place :(

Could it be because of the main domain (www.domain.com) is hosted on other server? Do they have to be together necessarily?

share|improve this question
    
You do not need to mark your titles with [solved]. You merely accept the correct answer. If a correct answer was not posted, you may create, and accept, your own answer. As it stands, your accept rate is 0%. This can discourage users from providing their input. –  jscott Jan 5 '11 at 12:46
    
Thx, didn't know that :P –  javipas Feb 14 '11 at 16:47

2 Answers 2

up vote 3 down vote accepted

First error I see right off the bat - location takes a regexp, you need to escape your . character. I suggest:

location ~* \.php$ {
}

You don't need *.domain.com, sugar.domain.com should be all that's needed. As koolhead17 mentions, make sure you set your DNS A record to the IP of this second server for sugar.domain.com; nginx will use the "Host" header coming from the browser and match it against server_name.

share|improve this answer
    
The DNS configuration was OK, I forgot to mention that. Thanks for the suggestion on the regexp, I'll try that, but I'm pretty sure the mistake is somewhere else: I did a minimal config file for sugar.domain.com on sites-enabled with just the listen, server_name and root parameters, and the same thing happened: the php code was not executed, just shown :O –  javipas Dec 30 '10 at 15:38
    
The regexp is not a suggestion, it is a fact. –  troyengel Dec 30 '10 at 17:29
    
troyengel, you were absolutelly right. Sorry for the delay, hadn't been able to test it until now :( SOLVED! xD –  javipas Jan 5 '11 at 11:12
    
good to hear! I see you have a 0% acceptance rate on Serverfault; on answers that solve your problem (like this one) on this site you're supposed to check the checkmark to "accept" the answer and close out the issue. It's right below the up/down arrows to vote on an answer. –  troyengel Jan 5 '11 at 15:04

I might be wrong but you have to Add a subdomain from your control panel say test.domain.com and map it with A record which will point to the IP on which your Nginx is running.

In the Nginx.conf you have to put the IP and subdomain in the virtualhost as we do in Apache.

share|improve this answer
    
If the OP is seeing the PHP source in a downloaded file from the URL then it's reaching the correct VHOST. –  Andrew Taylor Dec 30 '10 at 16:01

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.