Nginx and modern PHP frameworks problem

Discussion in 'Installation/Configuration' started by jang, Jun 11, 2015.

  1. jang

    jang New Member

    Most modern PHP frameworks (Laravel, Phalcon) have a project root (web) and a document root (web/public).
    Only the document root is accessible by web, and the project root is for composer, git and source files.
    (Tested it on a server Ubuntu 14.04 LTS and Nginx)

    ISPconfig3 has a default web directory, setup as document root.
    IMHO we need a setting in ISPcongif3 -> sites to set the root in Nginx to web/public instead of web.
    There are suggestions by Till how to do that but they do not work here, the only thing that works is editing ` /etc/nginx/sites-enabled/100-xx.vhost` and set the root manually, but that doesn't last.

    Adding another
    location / {
    root {docroot}/public
    }​
    sets the root only for that part.

    Furthermore I guess, more features to enable tweaking Nginx conf settings are needed / welcome.
    Of course a solution could be changing all your projects to work with the private folder, but that is a nuisance every time.

    So, is there a solution/workaround to change document root to web/public?
    The only hack I came with is manually copy /etc/nginx/sites-available/xx.vhost to /etc/nginx/sites-enabled/000-x.vhost so it will override the 100-x.vhost added by ISPconfig.

    Having web as document and project root for modern PHP frameworks is really insecure, IMHO it makes ISPconfig3 a bad choice for modern PHP frameworks, at least with default setup.
     
    Last edited: Jun 11, 2015
  2. till

    till Super Moderator Staff Member ISPConfig Developer

    Edit the nginx vhost template master file.
     
  3. jang

    jang New Member

    Thx Till, will try that out.
    Is this the file?

    /usr/local/ispconfig/server/conf/nginx_vhost.conf.master

    Will it be overridden with an update of ISP3config? Can I copy it to conf-custom, or is that a wrong idea?
     
  4. till

    till Super Moderator Staff Member ISPConfig Developer

    yes.

    Yes, the modified file should be stored in conf-custom toprevent that iz gets overridden on updates.
     
  5. jang

    jang New Member

    Thx, great help.
    Do you consider making this setting default or at least an installation option?
    IMHO It's good practice to limit the amount of PHP files in the document root. A different project and document root is really an improvement and for modern deployment a must.
     
  6. halycon

    halycon New Member

    I ran into that problem severals times now (changing nginx root). Till now i always used another webserver without ispconfig to run away from that problem, but now i need to get laravel running on vhost hosted at ispconfig nginx server.
    I don't get how this conf-custom thing works. I copied the
    Code:
    /usr/local/ispconfig/server/conf/nginx_vhost.conf.master
    to
    Code:
    /usr/local/ispconfig/server/conf-custom/nginx_vhost.conf.master
    and changed
    Code:
            root   <tmpl_var name='web_document_root_www'>;
    
    to
    Code:
            root   <tmpl_var name='web_document_root_www'>/public;
    
    And now? I don't get it, sorry.

    When creating a new website there is a dropdown to choose webserver configuration, but there is only one entry called "-".
     
  7. HSorgYves

    HSorgYves Active Member

    It will use your custom template when you click save, so you will have /public appended as you wish. Just try to save...
    P.S.: /public will be appended for all nginx conf files which are being (re)generated.
     
    halycon likes this.
  8. halycon

    halycon New Member

    Thanks, you're right. When i create a new website the conf-custom is used.
    I have several sites where i need the default config to be used and some laravel sites where i need the custom conf.
    What happens now with the file in conf-custom when i edit existing sites?

    Update: i just tried ...editing an existing site now applies the custom-conf if updated.
    How to avoid this? I need to specify only some sites to get the custom-conf.
     
  9. HSorgYves

    HSorgYves Active Member

    This doesn't work, you can modify a template but as I said in the P.S. before, it gets applied to all sites.
     
  10. till

    till Super Moderator Staff Member ISPConfig Developer

    What might work for you is using a vhost alias domain.
     

Share This Page