Apache2- need multiple projects with same domain that use different path after domain name - configuration

I have 2 completely different projects I would like to host from the same domain name "mysimpledomainname.com" with ip address xx.xx.xxx.xx (not local)
The 2 projects are located at
Project 1) /var/www/html/project1
Project 2) /var/www/html/project2
I would like to have the 2 projects resolve like this
Project 1
mysimpledomainname.com
project 2
mysimpledomainname.com/project2
I DO NOT want to use subdomain names. This is for a project on my public server, not my local machine, so I don't think updating the host file will help me.
I already have the first project loading from mysimpledomainname.com (it's already working).
In the directory sites-available I have the conf file mysimpledomainname.com.conf with values:
<VirtualHost *:80>
ServerAdmin myemail#gmail.com
DocumentRoot /var/www/html/project1
<Directory /var/www/html/project1/>
Options Indexes FollowSymLinks
AllowOverride All
Require all granted
RewriteEngine On
</Directory>
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
I think I need to have 2 different conf files set up in order to do this, but after searching around I have not been able to find a solution.
Can anyone help me with this? Rather than giving a short answer can you post exactly what I would need for the 2 different conf files?
Thanks,
David

You can have only 1 VirtualHost directive as this is defined per FQDN and you want to use only mysimpledomainname.com.
Your config for Project1 is OK. You just need to make available another directory under path /project2. To do this, you need to use the Alias directive.
So your final config should be something like this (of course you can have separate Directory configurations for each subdir if you want):
<VirtualHost *:80>
ServerAdmin myemail#gmail.com
DocumentRoot /var/www/html/project1
Alias /project2 /var/www/html/project2
<Directory /var/www/html/>
Options Indexes FollowSymLinks
AllowOverride All
Require all granted
RewriteEngine On
</Directory>
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>

Related

Different website through domain

I have a webserver, with 2 virtualhosts:
<VirtualHost *:80>
DocumentRoot /var/www/html
ServerName main.hu
LogLevel debug
</VirtualHost>
<VirtualHost *:80>
DocumentRoot /var/www/html/test.hu/
LogLevel debug
ServerAlias test.hu
ServerName www.test.hu
</VirtualHost>
When I query test.hu from any browser, it looks really weird, css looks different, menu is mixed etc. But when I check it with IP address for example 1.2.3.4/test.hu, it looks as it should be.
test.hu points to 1.2.3.4 in DNS.
I'm running a Centos 7 with httpd-2.4.6-18.
Selinux disabled.
Any ideas?
Looks like the bootstrap.min.css files being loaded are not the same in each version.
http://178.62.30.55/debergabor.hu/css/bootstrap.min.css
http://debergabor.hu/css/bootstrap.min.css
These should be the same but they are not. You have different versions so you have uploaded or linked the wrong files. The first one out of these 2 is the correct one.
So basically, go to where you hosted debergabor.hu, remove the bootstrap.min.css file, then upload the correct one.

Treating a subdirectory as a root directory for Apache

I cannot find a way to do what I want. I want to upload a project to my server at http://example.com/MyNewProject
In each of the web pages I include a file which does all of the imports for stylesheets, JavaScript etc. I don't want to provide the full path every time I just want to be able to do /MyStylesheet.css
My main websites document root is /var/www/html/example and my new projects directory is stored within /var/www/html/example/MyNewProject.
What I want is in my import when I do /MyStylesheet.css instead of going to my servers main web directory it will go to /var/www/html/example/MyNewProject in order to get the CSS.
I've tried adding the following to my Apache config file:
Alias /NewProjectTemplate "/var/www/html/example/NewProjectTemplate"
Alias /NewPRojectTemplate/ "/var/www/html/example/NewProjectTemplate"
<Directory "/var/www/html/example/NewProjectTemplate">
Options Indexes FollowSymLinks Includes
AllowOverride All
XBitHack On
Order allow,deny
Allow from all
</Directory>
This unfortunately hasn't worked so I've also tried adding the following to my virtualhosts file
<VirtualHost *:80>
DocumentRoot /var/www/html/example/NewProjectTemplate
ServerName example.com/NewProjectTemplate
</VirtualHost>
I've looked around on Google but cannot find anything specific, the only thing I've found is something to do with using the Rewrite engine but this seems a little too complicated and OTT for my needs.
Update
I've got a little further, although not a lot, I'm sure its not supposed to be this complicated.
Instead of using the virtual hosts, I'm now using an alias and below is what I've added to my httpd.conf file
DocumentRoot "/var/www/html"
Alias /NewTemp/ "/var/www/html/example/NewProjectTemplate/"
Alias /NewTemp "/var/www/html/example/NewProjectTemplate"
<Directory "/var/www/html/example/NewProjectTemplate/">
Options FollowSymLinks Includes
AllowOverride all
</Directory>
<Directory "/var/www/html/example/NewProjectTemplate">
Options FollowSymLinks Includes
AllowOverride all
</Directory>
In my HTML code in my SSI I am doing the following:
<!--#include file="includes/imports.html"-->
As you can see this is a relative path and Includes is inside the root of NewProjectTemplate. However, this is a template file so I want it to always to go to the root to find the file so it is guaranteed to work no matter how deep into the site it. For example if I change the line to the below I then get an error error processing directive
<!--#include file="/includes/imports.html"-->
So even though it works without the / but doesn't with the slash, if I don't include the slash so this import then works, the imports within the imports.html file work even though they do contain the leading slash so it always go to the root. Below is my HTML imports file
<link rel="stylesheet" type="text/css" href="/StyleSheet.css">
<link rel="stylesheet" type="text/css" href="/navigation/top-nav.css">
<link rel="stylesheet" type="text/css" href="/navigation/side-nav.css">
<script type="text/javascript" src="/scripts/jquery.js"></script>
<script type="text/javascript" src="/scripts/menu.js"></script>
So just to clarify, if the #include file = includes/imports.html the SSI directive works and /StyleSheet.css is successfully imported even though it has the leading slash. If I add a / to the path of the SSI it then doesn't get imported.
But here is where it gets weirder.
If I then add another file to a subdirectory e.g. NewProjectTemplate/MySubDirectory and then add the SSI to be ../includes/imports.html it still doesn't work. Its like the #include file SSI directive expects the file to be in the same working directory.
So, have you tried like this in the virtual host?
<VirtualHost *:80>
ServerAdmin emailaddress#domain.com
DocumentRoot "/var/www/html/example/"
ServerName example.local
ServerAlias example.local
<Directory "/var/www/html/example/">
Options All Includes Indexes FollowSymLinks
Order allow,deny
Allow from all
AllowOverride All
</Directory>
Alias /NewProjectTemplate /var/www/html/example/NewProjectTemplate
<Directory "/var/www/html/example/NewProjectTemplate">
Order allow,deny
Allow from all
</Directory>
</VirtualHost>
Hope it helps this time..
Just accidentally stumbled across this very old threat.
No need of host or alias if you just want a sub dir to be treated as root.
The way to do it is to amend the httpd.conf, there you will find
<Directory>
just update this line and add
<Directory "your/server/root/original_path/subpath">
# your options
</Directory>

Apache hangs with Django Application and Matplotlib

Very stuck here and I don't have a whole lot to go on. I had a django application up and running and I started playing around with graphing using NetworkX and Matplotlib to visualize some of the data for a poster. I then tried to use the site again and got the error:
'/var/www' is not a writable dir; you must set /var/www/.matplotlib to be a writable dir. You can also set environment variable MPLCONFIGDIR to any writable directory where you want matplotlib data stored
Which I resolved by chmod'ding the directory. The site's homepage then loads fine but when I try to load any other page that django renders apache just hangs. I set the log level to debug and tail'ed it but it's not showing any new requests or errors or anything, it just sorta hangs until the browser gives up. I then thought it must just be an error with something that I just did so I reverted back to a working version in my repo and am having the same problem. Django's test server is still running the site fine which is leading me to believe that it's a problem with apache (of the whole thing apache is the part I have the least experience with).
my httpd.conf looks like:
ServerName >> my server <<
TraceEnable off
AcceptFilter http none
AcceptFilter https none
EnableMMAP off
EnableSendfile off
<VirtualHost *:80>
ServerAdmin >> my email <<
ServerName >> my server <<
DocumentRoot /Web/public/
<Directory />
Options FollowSymLinks
AllowOverride None
</Directory>
<Directory /var/www/>
Options Indexes FollowSymLinks MultiViews
AllowOverride None
Order allow,deny
allow from all
</Directory>
WSGIScriptAlias / /home/$USER/$APP/$APP/wsgi.py
<Directory /Web/public/static>
Options -Indexes
</Directory>
Alias /static /Web/public/static
Alias /media /Web/public/media
ErrorLog /var/log/apache2/error.log
LogLevel debug
CustomLog /var/log/apache2/access.log combined
Alias /doc/ "/usr/share/doc/"
<Directory "/usr/share/doc/">
Options Indexes MultiViews FollowSymLinks
AllowOverride None
Order deny,allow
Deny from all
Allow from 127.0.0.0/255.0.0.0 ::1/128
</Directory>
</VirtualHost>
Please let me know if you have any thoughts, or need any more info.
Thanks!
I had the same problem; Apache/Django would not work but manage.py runserver would work fine. I tried making the default directory readable, and I tried changing MPLCONFIGDIR with export MPLCONFIGDIR=/stuff/, but the only thing that worked was placing
import os
os.environ[ 'MPLCONFIGDIR' ] = '/tmp/'
BEFORE importing matplotlib. Only one page uses MPL in my case, so placing this 'everywhere' was acceptable to me.
Taken from original solution by steko.

Files not showing up because looking at root but I think I specify the root!

I'm working locally and I always specify files as /files.jpg or whatnot so the server will always know to look at the root level to find the files. That way if I'm on a subpage it won't choke. But locally the files do not show up. My file structure is apache2/htdocs/name_of_folder. name_of_folder is my "root". I then modify my virtualhost file so when I enter localhost/name_of_folder it will show my site. I specify the DocumentRoot so I thought when I say localhost/name_of_folder that is working at the document root?
In httpd-vhosts.conf I have it set to
<VirtualHost *:80>
ServerAdmin webmaster#dummy-host.example.com
DocumentRoot "/opt/local/apache2/name_of_folder"
ServerName localhost/name_of_folder
ServerAlias www.localhost/name_of_folder
ErrorLog "logs/name_of_folder_log"
CustomLog "logs/name_of_folder_access_log" common
</VirtualHost>
What am I doing wrong?
You are misusing the ServerName and ServerAlias directives. They have nothing to do with files or paths. They are the domain name that identifies the web site (together with an optional port if not 80). If you want to move your document root, you have to edit the DocumentRoot directive.
You may not do this in that way. The directive ServerName is not supposed to get an URL but a domain name. Set the root to the parent folder, deny all access to it using <Directory> and allow access to you subdirectory to get it work.
In stead of doing:
ServerName localhost/name_of_folder
ServerAlias www.localhost/name_of_folder
Create a subdomain:
ServerName subdomain.localhost

Subdomain alias of subdomain

On a Linux Plesk server I want the following:
source-sub.domain.com
Aliases:
alias1.domain.com ->source-sub.domain.com
alias2.domain.com ->source-sub.domain.com
alias3.domain.com ->source-sub.domain.com
So I want several subdomains to point to the source sub domain. How do I do this? Can I make a symlink or something?
Just bumped into this myself.
Create a file vhost.conf in the subdomain conf folder:
/var/www/vhosts/domain.com/subdomains/source-sub/conf/vhost.conf
# add aliases to that file
ServerAlias alias1.domain.com
ServerAlias alias2.domain.com
ServerAlias alias3.domain.com
# reconfigure PSA's httpdmng
/usr/local/psa/admin/sbin/httpdmng --reconfigure-domain example.com