使用nginx/php-fpm为两个php应用程序提供服务?

使用nginx/php-fpm为两个php应用程序提供服务?,nginx,nginx-config,Nginx,Nginx Config,我想问一下,这是否是将php fpm与nginx config结合使用以服务于两个php应用程序的正确方法 server { listen 80 default_server; listen [::]:80 default_server; server_name _; root /usr/share/nginx/html; index index.html index.htm index.php;

我想问一下,这是否是将php fpm与nginx config结合使用以服务于两个php应用程序的正确方法

    server {
    listen       80 default_server;
    listen       [::]:80 default_server;
    server_name  _;
    root         /usr/share/nginx/html;
    index   index.html index.htm index.php;

    ## ==================
    ##  http to https
    ## ==================
    if ($http_x_forwarded_proto = "http") {
        return 301 https://$host$request_uri;
    }

    ## ==================
    ## /app1 - physical location: /usr/share/nginx/html/app1
    ## ==================
    location ^~ /app1 {
        try_files $uri $uri/ /app1/index.php?$args;
        auth_basic "xyz";
        auth_basic_user_file /usr/share/.htpasswd;

            location ~ \.php$ {
                fastcgi_index  index.php;
                fastcgi_intercept_errors on;
                include        fastcgi_params;
                fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
                fastcgi_pass   unix:/run/php-fpm/www.sock;
            }
    }

    ## ==================
    ## /app2 - physical location: /usr/share/nginx/html/app2
    ## ==================
    location ^~ /app2 {
        try_files $uri $uri/ /app2/index.php?$args;

            location ~ \.php$ {
                fastcgi_index  index.php;
                fastcgi_intercept_errors on;
                include        fastcgi_params;
                fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
                fastcgi_pass   unix:/run/php-fpm/www.sock;
            }
    }

}

也许可以将代码改进为只包含一个php/fastcgi参数块?

如果您想为每个与app1相关的请求保留HTTP基本身份验证,我认为答案是否定的,您不能减少配置以使用单个php处理程序位置。