Page 1 of 1

Define the document root path for a static content subdomain

Posted: Sat Jan 21, 2017 5:31 pm
by carival60
Hi there,

Mi name is Carlos and I'm recently started using a VPS server for my website.

VestaCP is a great control panel and I'm very pleased using it.

However, I have a small problem: can't find an easy way to define the document root path for a static content subdomain.

I created a domain.net's subdomain called static.domain.net to serve the content of images, audio and video for the main domain. The problem is that I could not find a way to define the document root path of the subdomain to point to the directory uploads in wp-content of my Wordpress installation.

On cpanel/zpanel/virtualmin it's pretty straightforward, define or change the subdomain document root path by editing it. Something like this: http://bit.ly/2k09HxO

In Vesta I haven't found any way of doing it. I found this in VestaCP Documentation but I don't know if it's what I need.

https://vestacp.com/docs/#how-to-point-subdomain-to-dir

Can someone point me to the right direction?

Many thanks in advance

Carlos A.

Re: Define the document root path for a static content subdomain

Posted: Sun Jan 29, 2017 6:26 pm
by vikhyat
Creating the sub domain site is the same as creating a top level domain site. Just go to the WEB section and click add website and type "subdomain.topdomain.tld" and you are good to go!

Re: Define the document root path for a static content subdomain

Posted: Mon Jan 30, 2017 6:19 am
by carival60
vikhyat wrote:Check Step 7 of the tutorial on this website if you still have doubt http://blog.flaunt7.com/host-new-websit ... rol-panel/
Hello vikhyat, thanks for helping me with this.

I don't know if I explained well in the first post. I already have the subdomain created and configured correctly. The problem is, that I want the subdomain to serve static content (imgs, audio and video) to a wordpress site that works with the main domain. When I had the website in my old shared hosting with cpanel, there was a way to define the document root path of the subdomain, which pointed to the Uploads directory in the wordpress installation. So when uploading an image through the wordpress media library, that image was stored in the uploads folder, but was served through the subdomain to the website. What I need is the way to accomplish that the media.domain.com points to the upload folder in my wordpress instalation, in VestaCP, without having to load the same content twice. Domain and subdomain are in the same server and in the same user account.

Thanks in advanced

Carlos A.

Re: Define the document root path for a static content subdomain

Posted: Mon Jan 30, 2017 12:45 pm
by mehargags
carival60 wrote: I created a domain.net's subdomain called static.domain.net to serve the content of images, audio and video for the main domain. The problem is that I could not find a way to define the document root path of the subdomain to point to the directory uploads in wp-content of my Wordpress installation.
The easiest way is to edit your apache2 conf file (I'm on Debian):

nano /home/<user>/conf/web/apache2.conf

Find your domain virtual host

<VirtualHost IP:8080>

ServerName abc.xyz
ServerAlias www.abc.xyz
DocumentRoot /home/<user>/web/abc.xyz/public_html


Replace public_html with your full path. For example the root path of the subdomains is

/home/admin/web/sub.domain/public_html/wp-content/uploads

Then

Code: Select all

service apache2 restart 
or

Code: Select all

service httpd restart
Please adjust above commands for CentOS, I'm a devoted Debian user... ha ha!

Re: Define the document root path for a static content subdomain

Posted: Mon Jan 30, 2017 12:49 pm
by mehargags
vikhyat wrote:Creating the sub domain site is the same as creating a top level domain site. Just go to the WEB section and click add website and type "subdomain.topdomain.tld" and you are good to go!
vikhyat wrote:Check Step 7 of the tutorial on this website if you still have doubt http://blog.flaunt7.com/host-new-websit ... rol-panel/
Vikhyat... Again you are trying to deviate user from the actual solution with your incomplete understanding and knowledge. He is not asking for "how to create a subdomain" he is asking how to change document root for a website, which obviously you have no idea about. Please refrain from replying until you know what you are saying.

Re: Define the document root path for a static content subdomain

Posted: Tue Feb 07, 2017 6:18 pm
by carival60
mehargags wrote:
carival60 wrote: I created a domain.net's subdomain called static.domain.net to serve the content of images, audio and video for the main domain. The problem is that I could not find a way to define the document root path of the subdomain to point to the directory uploads in wp-content of my Wordpress installation.
The easiest way is to edit your apache2 conf file (I'm on Debian):

nano /home/<user>/conf/web/apache2.conf

Find your domain virtual host

<VirtualHost IP:8080>

ServerName abc.xyz
ServerAlias www.abc.xyz
DocumentRoot /home/<user>/web/abc.xyz/public_html


Replace public_html with your full path. For example the root path of the subdomains is

/home/admin/web/sub.domain/public_html/wp-content/uploads

Then

Code: Select all

service apache2 restart 
or

Code: Select all

service httpd restart
Please adjust above commands for CentOS, I'm a devoted Debian user... ha ha!

Thanks, mehargags

I think, for what I've researched, this is the right way, but by somehow I can't make it work.

I learned a lot since I moved from shared hosting to VPS. By myself installed a lot of Control Panels and, at the end, stayed with Vesta, but here, I feel that I'm missing something.

To be clear, I just want to serve the static content from the upload folder in my WordPress installation (domain.com) through the subdomain media.domain.com, configuring the document root path of the subdomain pointing to the uploads folder in domain.com. I configured the upload URL path (in WordPress) to: https://media.domain.com and I tried your solution but I failed to make it work. The images are uploaded to the media library but they are not showed (like this: http://bit.ly/2kJIv9F).

I have Vesta CP installed on CentOS 7, Apache as HTTPD and Nginx as proxy. I have Let's Encrypt SSL Cert at Control Panel, domain and subdmain.

When I edit the httpd.conf and nginx.conf files, I found this:

httpd.conf

Code: Select all


<VirtualHost 123.45.67.890:8080>

    ServerName media.domain.com

    ServerAdmin info@media.domain.com
    DocumentRoot /home/admin/web/media.domain.com/public_html
    ScriptAlias /cgi-bin/ /home/admin/web/media.domain.com/cgi-bin/
    Alias /vstats/ /home/admin/web/media.domain.com/stats/
    Alias /error/ /home/admin/web/media.domain.com/document_errors/
    #SuexecUserGroup admin admin
    CustomLog /var/log/httpd/domains/media.domain.com.bytes bytes
    CustomLog /var/log/httpd/domains/media.domain.com.log combined
    ErrorLog /var/log/httpd/domains/media.domain.com.error.log
    <Directory /home/admin/web/media.domain.com/public_html>
        AllowOverride All
        Options +Includes -Indexes +ExecCGI
        php_admin_value open_basedir /home/admin/web/media.domain.com/public_html:/home/admin/tmp
        php_admin_value upload_tmp_dir /home/admin/tmp
        php_admin_value session.save_path /home/admin/tmp
    </Directory>
    <Directory /home/admin/web/media.domain.com/stats>
        AllowOverride All
    </Directory>

    <IfModule mod_ruid2.c>
        RMode config
        RUidGid admin admin
        RGroups apache
    </IfModule>
    <IfModule itk.c>
        AssignUserID admin admin
    </IfModule>

    IncludeOptional /home/admin/conf/web/httpd.media.domain.com.conf*

</VirtualHost>
And nginx.conf

Code: Select all

server {
    listen      123.45.67.890:80;
    server_name media.domain.com;
    error_log  /var/log/httpd/domains/media.domain.com.error.log error;

    location / {
        proxy_pass      http://123.45.67.890:8080;
        location ~* ^.+\.(jpeg|jpg|png|gif|bmp|ico|svg|tif|tiff|css|js|htm|html|ttf|otf|webp|woff|txt|csv|rtf|doc|docx|xls$
            root           /home/admin/web/media.domain.com/public_html;
            access_log     /var/log/httpd/domains/media.domain.com.log combined;
            access_log     /var/log/httpd/domains/media.domain.com.bytes bytes;
            expires        max;
            try_files      $uri @fallback;
        }
    }

    location /error/ {
        alias   /home/admin/web/media.domain.com/document_errors/;
    }

    location @fallback {
        proxy_pass      http://123.45.67.890:8080;
    }

    location ~ /\.ht    {return 404;}
    location ~ /\.svn/  {return 404;}
    location ~ /\.git/  {return 404;}
    location ~ /\.hg/   {return 404;}
    location ~ /\.bzr/  {return 404;}

    include /home/admin/conf/web/nginx.media.domain.com.conf*;
}
I changed the document root path of the subdomain as you suggested, restart HTTPD and nothing happens. So I changed the document root path also in the nginx.conf, restart nginx and HTTPD and nothing happens. I try to imitate the configuration of the document root path in Cpanel (ex-host) and nothing happens. I feel I'm close but can't get there.

Which part of these codes do I have to edit in order make it work? What other settings do I have to configure in WordPress so that the images are showed correctly?

Thanks again for your help...

Carlos A.

Re: Define the document root path for a static content subdomain

Posted: Wed Feb 08, 2017 9:28 am
by mehargags
This is correct way to define

Code: Select all

DocumentRoot /home/admin/web/media.domain.com/public_html
in your nginx I see "root" defined... are you not running nginx as Rev. proxy ?
you should just have proxy_pass http://xxx.xxx.xxx.xxx:8080; section there.

I'm not sure what you've done till now but I feel the conf's have been fiddled way beyond the need... you might get lost in configuring them.

Re: Define the document root path for a static content subdomain

Posted: Wed Feb 08, 2017 8:02 pm
by carival60
mehargags wrote:This is correct way to define

Code: Select all

DocumentRoot /home/admin/web/media.domain.com/public_html
in your nginx I see "root" defined... are you not running nginx as Rev. proxy ?
you should just have proxy_pass http://xxx.xxx.xxx.xxx:8080; section there.

I'm not sure what you've done till now but I feel the conf's have been fiddled way beyond the need... you might get lost in configuring them.

Thanks, mehargags

Yes, I'm running Apache as HTTPD and Nginx as a Reverse Proxy.

In the nginx.conf file, I have the two proxy_pass correctly, because I did a copy of the two original files (httpd.conf and nginx.conf) before making any change on them.

Thanks again...

Re: Define the document root path for a static content subdomain

Posted: Fri May 18, 2018 4:27 pm
by rhyker2u
Hey there :) Ran in through this topic through a Google search. And while this might be true:
mehargags wrote:
Mon Jan 30, 2017 12:45 pm
The easiest way is to edit your apache2 conf file (I'm on Debian):

nano /home/<user>/conf/web/apache2.conf
... it also goes wrong then in the event of rebuilding vesta. Moreover the proposed solutions are invalid. As the subdomain that gets defined in VestaCP (for SSL to work properly); is pointing towards the wrong (document)root! It has to direct to the main domain instead, and not the sub. It did give me an idea just now to write a seperate VestaCP template for that (for both nginx as well as apache2): 'brb'.

*couple of hours later* hmz. Easier said than done. Thusfar unable to seperate the 'alias' part from the %domain_idn% hence a subdomain template -- which makes the most sense -- is quite daunting. And creating a 2nd virtualhost within the default template specifically to handle 'media' or 'static' subdomain through conditional expressions should be possible, but haven't quite figured it all out yet how it could be done VestaCP templates. :-(

*edit2* Manually editing *.conf files might seem easier but gets complicated fast too. Giving up on it myself for now. And just benefit from caching plugins + generic CDNs instead, to accomplish the same (cookie-less domains). P.S. a great walkthrough for the Cpanel guide: https://www.itsupportguides.com/knowled ... ss-domain/ ... in case someone likes to pick up on the idea for VestaCP (to fully understand what it is about and work towards a solution).

Re: Define the document root path for a static content subdomain

Posted: Sat Jun 08, 2019 11:01 am
by yoyomolen
I'm trying to achieve the same, but the nano /home/admin/conf/web/apache2.conf opens up an empty file. Please help?
Thanks