We are happy to announce that Vesta is back under active development as of 25 February 2024. We are working on v1 candidate and expect to engage more with the community over the coming months. We are committed to open source, and we encourage contributors to help us build the future of Vesta.
Define the document root path for a static content subdomain
Define the document root path for a static content subdomain
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.
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
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
Hello vikhyat, thanks for helping me with this.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/
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.
-
- Support team
- Posts: 1096
- Joined: Sat Sep 06, 2014 9:58 pm
- Contact:
- Os: Debian 8x
- Web: apache + nginx
Re: Define the document root path for a static content subdomain
The easiest way is to edit your apache2 conf file (I'm on Debian):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.
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
Code: Select all
service httpd restart
-
- Support team
- Posts: 1096
- Joined: Sat Sep 06, 2014 9:58 pm
- Contact:
- Os: Debian 8x
- Web: apache + nginx
Re: Define the document root path for a static content subdomain
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... 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.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/
Re: Define the document root path for a static content subdomain
mehargags wrote:The easiest way is to edit your apache2 conf file (I'm on Debian):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.
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
ThenorCode: Select all
service apache2 restart
Please adjust above commands for CentOS, I'm a devoted Debian user... ha ha!Code: Select all
service httpd restart
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 [email protected]
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>
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*;
}
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.
-
- Support team
- Posts: 1096
- Joined: Sat Sep 06, 2014 9:58 pm
- Contact:
- Os: Debian 8x
- Web: apache + nginx
Re: Define the document root path for a static content subdomain
This is correct way to define
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.
Code: Select all
DocumentRoot /home/admin/web/media.domain.com/public_html
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
mehargags wrote:This is correct way to definein your nginx I see "root" defined... are you not running nginx as Rev. proxy ?Code: Select all
DocumentRoot /home/admin/web/media.domain.com/public_html
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
Hey there :) Ran in through this topic through a Google search. And while this might be true:
*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).
... 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
I'm trying to achieve the same, but the nano /home/admin/conf/web/apache2.conf opens up an empty file. Please help?
Thanks
Thanks