Score:0

NGINX display first site in subdirectory of second

my flag

The problem is:

First site firstsite.test runs on PHP 7.4, I need to launch second site on PHP 8.0 and another framework inside its subdirectory: firstsite.test/second-site/

So, now I have 2 separate nginx conf for each sites and they are workinbg separately.

But I cant make second site to be shown on first site subdirectory. What I tried:

  1. Make an alias in first site conf:
server {
 listen IP:port;
 root /var/www/user/data/www/firstsite/current;

 location @php {
        fastcgi_index index.php;
        fastcgi_param PHP_ADMIN_VALUE "sendmail_path = /usr/sbin/sendmail -t -i -f [email protected]";
        fastcgi_pass unix:/var/www/php-fpm/1.sock;
        fastcgi_split_path_info ^((?U).+\.ph(?:p\d*|tml))(/?.+)$;
        try_files $uri =404;
        include fastcgi_params;
    }

 location  ~ ^/second-site/ {
        alias /var/www/user/data/www/secondsite/current/public;
 
        add_header X-Frame-Options "SAMEORIGIN";
        add_header X-Content-Type-Options "nosniff";
     
        index index.php;
     
        charset utf-8;
    
        try_files $uri $uri/ /index.php?$query_string;
        
     
        location ~ \.php$ {
            fastcgi_pass unix:/var/www/php-fpm/18.sock;
            fastcgi_param SCRIPT_FILENAME $realpath_root$fastcgi_script_name;
            include fastcgi_params;
        }
     
        location ~ /\.(?!well-known).* {
            deny all;
        }
    }
}
  1. Set root path:
server {
 listen IP:port;
 root /var/www/user/data/www/firstsite/current;

 location @php {
        fastcgi_index index.php;
        fastcgi_param PHP_ADMIN_VALUE "sendmail_path = /usr/sbin/sendmail -t -i -f [email protected]";
        fastcgi_pass unix:/var/www/php-fpm/1.sock;
        fastcgi_split_path_info ^((?U).+\.ph(?:p\d*|tml))(/?.+)$;
        try_files $uri =404;
        include fastcgi_params;
    }

 location  ~ ^/second-site/ {
        root /var/www/user/data/www/secondsite/current/public;
 
        add_header X-Frame-Options "SAMEORIGIN";
        add_header X-Content-Type-Options "nosniff";
     
        index index.php;
     
        charset utf-8;
    
        try_files $uri $uri/ /index.php?$query_string;
        
     
        location ~ \.php$ {
            fastcgi_pass unix:/var/www/php-fpm/18.sock;
            fastcgi_param SCRIPT_FILENAME $realpath_root$fastcgi_script_name;
            include fastcgi_params;
        }
     
        location ~ /\.(?!well-known).* {
            deny all;
        }
    }
}

Nothing of this works. Please, point me to right way.

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.