1. Please take a little time for this simple survey! Thank you for participating!
    Dismiss Notice
  2. Dear Pleskians, please read this carefully! New attachments and other rules Thank you!
    Dismiss Notice
  3. Dear Pleskians, I really hope that you will share your opinion in this Special topic for chatter about Plesk in the Clouds. Thank you!
    Dismiss Notice

Nginx configuration for vhosts

Discussion in 'Plesk 11.x for Linux' started by akcontreras, Jul 3, 2012.

  1. akcontreras

    akcontreras New Pleskian

    10
    35%
    Joined:
    Jul 3, 2012
    Messages:
    5
    Likes Received:
    0
    How can I customize/add a configuration for a vhost in nginx. I want to put proxy_pass for Node.js into a subdomain of a vhost. All files I look it says: DO NOT MODIFY THIS FILE BECAUSE IT WAS GENERATED AUTOMATICALLY
     
  2. abdi

    abdi Platinum Pleskian

    31
    18%
    Joined:
    May 14, 2006
    Messages:
    2,913
    Likes Received:
    60
    You can modify the default template by

    vim /usr/local/psa/admin/conf/templates/default/domain/domainVirtualHost.php

    and then,

    /usr/local/psa/admin/sbin/httpdmng --reconfigure-all
     
  3. akcontreras

    akcontreras New Pleskian

    10
    35%
    Joined:
    Jul 3, 2012
    Messages:
    5
    Likes Received:
    0
    1.- Is with Nginx but thanks, is the right clue what I needed.
    2.- That will be global, I need only 1 domain, it will be nice if I could modify just 1 domain and the changes will keep
     
  4. orlandotom

    orlandotom Guest

    0
     
    I need to know how to do this on a per domain basis as well. The template helps somewhat (and I've used it for the time being), but most of the time, I want to be able to change the nginx settings on a per domain basis, not have my changes appear globally for all domains. What is the equivalent of vhost.conf (in /var/www/vhosts/domain/conf/) for nginx
     
  5. abdi

    abdi Platinum Pleskian

    31
    18%
    Joined:
    May 14, 2006
    Messages:
    2,913
    Likes Received:
    60
    there is a file in /var/www/vhosts/domain/conf/ that is called "last_nginx.conf" that is what you edit and then thereafter you can run:

    Code:
    /usr/local/psa/admin/sbin/httpdmng --reconfigure-domain <domain_name>
     
  6. orlandotom

    orlandotom Guest

    0
     
    I know you can edit that file, that will not however affect changes moving forward when running:
    /usr/local/psa/admin/sbin/httpdmng --reconfigure-domain
    As the file states:
    As a matter of fact, when you run httpdmng --reconfigure-domain, you will actually lose the changes you just made (this is why you add a vhost.conf file, NOT edit last_httpd.include)

    the file you could edit is <newest_version>_nginx.conf and then restart nginx
    running /usr/local/psa/admin/sbin/httpdmng --reconfigure-domain will once again, wipe out those changes

    So what is the nginx.conf (could it be nginx.conf??) file that can be added on a per domain basis, that
    /usr/local/psa/admin/sbin/httpdmng --reconfigure-domain will then pull in and include in the auto generated file.
     
  7. orlandotom

    orlandotom Guest

    0
     
    It looks like the auto generated nginx.conf files on a per domain basis do NOT include any type of mechanism to include per domain additions.

    This can be added however it looks like. The nginx configure files do support the ability to include other files.

    What you will want to do is edit the nginx template file, located at:
    /usr/local/psa/admin/conf/templates/default/domain/nginxDomainVirtualHost.php

    Add a line like:
    include <?php echo $VAR->domain->physicalHosting->vhostDir;?>/conf/nginx.conf;

    I don't have any recommendations as to where to place this, I am sure it depends if you want to add new listeners, overwrite listeners (I haven't played with nginx enough yet, but I would assume, the last definition would overwrite a previous definition), or just add new locations and proxy's.

    Then add your own nginx.conf file in the /var/www/vhosts/domain/conf folder

    One stumbling point: This will cause httpdmng --rebuilt-all to fail, if any domain does not have the new file. Adding a php test if file_exists will probably help solve this.
     
    Last edited by a moderator: Jul 6, 2012
  8. abdi

    abdi Platinum Pleskian

    31
    18%
    Joined:
    May 14, 2006
    Messages:
    2,913
    Likes Received:
    60
    Well you can lock the file against changes in it by:

    Code:
    chattr +i last_nginx.conf
     
  9. OlegN

    OlegN Basic Pleskian Staff Member

    23
     
    Joined:
    Nov 18, 2009
    Messages:
    89
    Likes Received:
    1
    Using of immutable bit on such files can brake plesk upgrade sometimes.

    Here steps how to add custom include in nginx virtual host config:

    mkdir /usr/local/psa/admin/conf/templates/custom/domain

    cp /usr/local/psa/admin/conf/templates/default/domain/nginxDomainVirtualHost.php /usr/local/psa/admin/conf/templates/custom/domain/

    add in /usr/local/psa/admin/conf/templates/custom/domain/nginxDomainVirtualHost.php:

    <?php if (file_exists($VAR->domain->physicalHosting->vhostDir . '/conf/nginx.conf')): ?>
    include <?php echo $VAR->domain->physicalHosting->vhostDir;?>/conf/nginx.conf;
    <?php endif ?>

    /usr/local/psa/admin/bin/httpdmng --reconfigure-all # to apply new configuration for all domains

    As result, if domain has conf/nginx.conf - it will be included into virtual host config.
     
  10. Nikolay.

    Nikolay. Silver Pleskian

    17
    35%
    Joined:
    Jul 1, 2012
    Messages:
    844
    Likes Received:
    2
    Great advice by OlegN!

    Though I should note that this solution will break apart during upgrade to Plesk 11.5 (where this functionality is present out of the box).

    After upgrade to 11.5 you'll need to move your custom configs to conf/vhost_nginx.conf, remove custom template and call httpdmng --reconfigure-all.

    Oh, and really avoid using chattr +i even if your filesystem supports it.
     
  11. Zwilla

    Zwilla New Pleskian

    6
     
    Joined:
    Aug 1, 2013
    Messages:
    1
    Likes Received:
    0
    Thx. It Works!

    Great Job OLEG

    5 Stars

    And also Nikolay!

    If you wan´t to edit the file after:

    chattr +i nginx.conf

    then execute

    chattr -i nginx.conf

    * Edit the file and
    chattr +i nginx.conf
    again
     
    Last edited: Aug 1, 2013
  12. javismiles

    javismiles New Pleskian

    6
    70%
    Joined:
    Mar 21, 2014
    Messages:
    9
    Likes Received:
    0
    i now tried something different, in plesk 11.5
    i went to web server settings of the subdomain
    and in extra nginx directives i added
    location ~ /$ {
    root /var/www/vhosts/domain.com/httpdocs;
    }

    that changed that now when going to
    secure.domain.com instead of getting a 404 not found,
    i get a 403 forbidden

    other than that if i try
    secure.domain.com/index.php i still get 404 error and same for other files
     
  13. javismiles

    javismiles New Pleskian

    6
    70%
    Joined:
    Mar 21, 2014
    Messages:
    9
    Likes Received:
    0
    dear friends
    so i have created a subdomain secure.domain.com and i pointed it to the main folder of domain.com,
    i created custom vhost.conf for apache and that works great,
    but nginx is pointing still to wrong folder, logical as i can see that the last_nginx.conf file is pointing to wrong place

    so i found the thread http://forum.parallels.com/showthread.php?260814-Nginx-configuration-for-vhosts
    and i followed the indications there but its not working for me,

    - i have edited a file nginxDomainVirtualHost.php
    on /usr/local/psa/admin/conf/templates/custom/domain
    after copying from the default folder
    and i added this as you indicated
    <?php if (file_exists($VAR->domain->physicalHosting->vhostDir . '/conf/nginx.conf')): ?>
    include <?php echo $VAR->domain->physicalHosting->vhostDir;?>/conf/nginx.conf;
    <?php endif ?>

    just i wasnt sure where to add it, i added it at the very end before the last }
    is that correct, or if not where should i add it within that file?

    and then i added an nginx.conf inside
    /var/www/vhosts/system/secure.domain.com/conf

    and inside i just put
    root "/var/www/vhosts/domain.com/httpdocs"

    is that correct, or do i have to put more directives inside this custom nginx.conf?

    and then i did of course the /usr/local/psa/admin/bin/httpdmng --reconfigure-all
    but nothing happened

    when i go to secure.domain.com i keep getting 404 nginx errors,
    however the apache is pointing to right place because the .htaccess of main folder is getting processed, so apache all good,
    but all php and non php pages are failing with 404 nginx errors still

    i now tried something different, in plesk 11.5
    i went to web server settings of the subdomain
    and in extra nginx directives i added
    location ~ /$ {
    root /var/www/vhosts/domain.com/httpdocs;
    }

    that changed that now when going to
    secure.domain.com instead of getting a 404 not found,
    i get a 403 forbidden

    other than that if i try
    secure.domain.com/index.php i still get 404 error and same for other files


    thank you for any help
    best
     
Loading...