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.

How do I map the subdomain that I don't have to rewrite the URI?

server {
    listen       80;
    server_name  cooking.com user.cooking.com admin.cooking.com;
    root   html/cooking/public;

    location / {
        index  index.html index.htm index.php;
        try_files $uri $uri/ /index.php?$args;
    }

    location ~ \.php$ {
        fastcgi_pass   127.0.0.1:9000;
        fastcgi_index  index.php;
        fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
        fastcgi_param  FEED_ENV  default;
        include        fastcgi_params;
    }
    location ~* \.(ico|css|js|gif|jpe?g|png)$ {
        expires max;
        add_header Pragma public;
        add_header Cache-Control "public, must-revalidate, proxy-revalidate";
    }
}

So basically WHen a user access admin.cooking.com it should request for /index.php/admin/. I was thinking of using if but if is bad.

share|improve this question
    
How many of these hosts do you have? –  Michael Hampton Jul 30 '12 at 15:53
    
what do you mean @MichaelHampton –  Pineapple Under the Sea Jul 30 '12 at 20:02
    
Are you just trying to set up two subdomains, or more, or all of them? –  Michael Hampton Jul 30 '12 at 20:03
    
only the two subdomains @MichaelHampton –  Pineapple Under the Sea Jul 30 '12 at 20:05
    
How URL does passed to PHP? You should use fastcgi_param URL_VAR ...; and several server blocks. –  VBart Jul 30 '12 at 22:50

1 Answer 1

up vote 3 down vote accepted

You need separate server blocks for this.

# /etc/nginx/sites-available/php.conf

location @php {
  fastcgi_param FEED_ENV default;
  fastcgi_index index.php;
  fastcgi_pass 127.0.0.1:9000;
}

... and your server config:

# /etc/nginx/sites-available/server.conf;

listen 80;
root html/cooking/public;
index index.html index.htm index.php;
include fastcgi_params;

location / {
  location ~* \.(ico|css|js|gif|jpe?g|png)$ {
    expires max;
    add_header Pragma public;
    add_header Cache-Control "public, must-revalidate, proxy-revalidate";
  }
  try_files $uri $uri/ @php;
}

... and your final virtual host config:

# /etc/nginx/sites-available/virtual_hosts.conf

server {
  server_name cooking.com;
  include sites-available/server.conf;
  fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
  include sites-available/php.conf;
}

server {
  server_name user.cooking.com;
  include sites-available/server.conf;
  fastcgi_param  SCRIPT_FILENAME  $document_root/index.php/user/$args;
  include sites-available/php.conf;
}

server {
  server_name admin.cooking.com;
  include sites-available/server.conf;
  fastcgi_param  SCRIPT_FILENAME  $document_root/index.php/admin/$args;
  include sites-available/php.conf;
}

You only create a symbolic link in sites-enabled to the virtual_hosts.conf!

Because I don't know your exact environment (the backend and how it handles the incoming URLs) I can't give you a perfect config. But this should be a good starting point.

share|improve this answer
    
that can't be because it must make the request on the index.php file, admin and user are not a directory. –  Pineapple Under the Sea Aug 21 '12 at 2:52
    
I edited my answer. –  Fleshgrinder Aug 21 '12 at 10:36

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.