nginx配置中的多个应用程序

时间:2013-08-18 15:04:35

标签: nginx

我有php应用程序,由三部分分隔:前端,后端,api。我需要将子域映射到这样的根:

  1. frontend.domain.com / domain.com - > frontend / www(index.php)
  2. backend.domain.com - > backend / www(index.php)
  3. api.domain.com / domain.com/api - > api / www(index.php)
  4. 我当前的nginx配置:

    server {
        listen 80;
    
        server_name ~^(?<subdomain>(api|frontend|backend))\.domain\.com$ domain.com;
    
        if ($subdomain = '') {
            set $subdomain 'frontend';
        }
    
        root  /var/www/domain/$subdomain/www;
        index index.php;
    
        access_log  /var/log/nginx/domain.access.log;
        error_log  /var/log/nginx/domain.error.log;
    
        location / {
            try_files $uri $uri/ /index.php?$args;
        }
    
        location ~ \.php$ {
            fastcgi_pass unix:/var/run/php5-fpm.sock;
            fastcgi_split_path_info ^(.+\.php)(/.*)$;
            include fastcgi_params;
            fastcgi_param  SCRIPT_FILENAME $document_root$fastcgi_script_name;
        }
    }
    

0 个答案:

没有答案