Shared app in domain subfolder on Nginx with existing WordPress in root

Discussion in 'General' started by Steveorevo, Jul 16, 2022.

  1. Steveorevo

    Steveorevo Member

    Greetings everyone. I've been scratching my head trying to get this to work on Ubuntu 20.04.4 LTS, ISPConfig 3.2.8p1 to no avail. I have several testing WordPress websites (i.e. sites https://test1.example.com and https://test2.example.com). I'd like them to leverage a shared app that's in /usr/share/php/my-app. This app I created needs to take GET arguments and POST requests.

    Ideally my app would be accessible in each of the hosted domains in a subfolder: i.e. https://test1.example.com/my-app, https://test2.example.com/my-app. For the given WordPress websites I have the following Nginx directives to serve up WordPress in the root /web folder; this works well:

    Code:
        # Allow liberal uploads
        client_max_body_size 512m;
        index index.php;
        location = /favicon.ico {
            log_not_found off;
            access_log off;
        }
        location = /robots.txt {
            allow all;
            log_not_found off;
            access_log off;
        }
        # Support WordPress permalinks
        location / {
            try_files $uri $uri/ /index.php?$args;
        }
    
    But I'm having a heck of a time trying to get the contents of /usr/share/php/my-app serve up at all. I've poured over Nginx directives and am reading up on fastcgi definitions but no luck. There doesn't appear to be documentation in the guides I've purchased for ISPConfig's variables in the Nginx Directives section (such as {DOCROOT}, {DOCROOT_CLIENT}, {DOMAIN}, {FASTCGIPASS}, etc) but those seem pretty self explanatory. I've tried appending the following directives for a given client to try to get a working shared subfolder app i.e. https://test1.example.com/my-app but I just get a 404.
    Code:
        # Serve up my-app
        location ^~ /my-app {
            alias /usr/share/php/my-app;
            try_files $uri $uri/ /index.php?$args;
            include /etc/nginx/fastcgi_params;
            {FASTCGIPASS}
            fastcgi_index index.php;
            fastcgi_param DOCUMENT_ROOT /web;
            fastcgi_param HOME /web;
            fastcgi_param SCRIPT_FILENAME /web$fastcgi_script_name;
            fastcgi_intercept_errors on;
        }
    
    I know phpmyadmin does something similar as a "shared app" between all clients. I do need my shared app to read the contents of original /web folder (if possible) to include client specific settings unique to the client's own /web folder (i.e. $config = file_get_contents( '/web/config.php' ); ) Is this possible? Any help or suggestions for good reading appreciated.
     
  2. ahrasis

    ahrasis Well-Known Member HowtoForge Supporter

    https://www.howtoforge.com/tutorial...fig-3/2/#-install-hhvm-hiphop-virtual-machine

    Just before the above, there is code to be added as nginx directives which must be added in each vhost:
    Code:
           location /phpmyadmin {
                  root /usr/share/;
                  index index.php index.html index.htm;
                  location ~ ^/phpmyadmin/(.+\.php)$ {
                          try_files $uri =404;
                          root /usr/share/;
                          fastcgi_pass unix:/var/run/php/php7.2-fpm.sock;
                          fastcgi_param HTTPS $fastcgi_https; # <-- add this line
                          fastcgi_index index.php;
                          fastcgi_param SCRIPT_FILENAME $request_filename;
                          include /etc/nginx/fastcgi_params;
                          fastcgi_param PATH_INFO $fastcgi_script_name;
                          fastcgi_buffer_size 128k;
                          fastcgi_buffers 256 4k;
                          fastcgi_busy_buffers_size 256k;
                          fastcgi_temp_file_write_size 256k;
                          fastcgi_intercept_errors on;
                  }
                  location ~* ^/phpmyadmin/(.+\.(jpg|jpeg|gif|css|png|js|ico|html|xml|txt))$ {
                          root /usr/share/;
                  }
           }
           location /phpMyAdmin {
                  rewrite ^/* /phpmyadmin last;
           }
    
    Have you tried something similar to that first?
     
    Steveorevo likes this.
  3. Steveorevo

    Steveorevo Member

    Thank you ahrasis! Copying the phpmyadmin block and using that as a template appears to work well. :)
     
    ahrasis likes this.

Share This Page