NGINX, forwarding few localhosts to php-fpm

前端 未结 1 523
夕颜
夕颜 2021-01-25 10:47

I\'ve stuck on simple thing, please help. I have 2 directories with PHP projects: /var/www/api/ and /var/www/api-beta/. I want to forwarding each of them to PHP-FPM. Nginx confi

相关标签:
1条回答
  • 2021-01-25 11:09

    It may be simpler to create a location block for each PHP root:

    server {
        listen 80;
        root /var/www/api;
        index  index.php index.html;
    
        location ~ \.php$ {
            try_files $uri =404;
    
            include /etc/nginx/fastcgi_params;
            fastcgi_param  SCRIPT_FILENAME  $request_filename;
            fastcgi_pass   unix:/var/run/php/php7.0-fpm.sock;
        }
    
        location ^~ /beta {
            alias /var/www/api-beta;
    
            location ~ \.php$ {
                if (!-f $request_filename) { return 404; }
    
                include /etc/nginx/fastcgi_params;
                fastcgi_param  SCRIPT_FILENAME  $request_filename;
                fastcgi_pass   unix:/var/run/php/php7.0-fpm.sock;
            }
        }
    }
    

    Notes:

    • avoid using alias and try_files together. See this long standing issue.
    • the ^~ modifier cause the prefix location to take precedence over the regular expression location above. See this document for more.
    0 讨论(0)
提交回复
热议问题