I was wondering if I can set the server external IP as a domain for testing.
On my Amazon server setup it works because all the domains point to the same folder.
domain1.com - /var/www/domain1
domain2.com - /var/www/domain2
ex.ter.nal.ip - /var/www/
So I can use ex.ter.nal.ip/test for a testing website.
On my Linode setup I moved the folders inside the user directories
domain1.com - /home/user1/public/domain1
domain2.com - /home/user2/public/domain2
ex.ter.nal.ip goes to domain2.com (I think it points to the last enabled site in Apache -a2ensite)
Is there a way to make it work?
I tried adding a vhost with with the /home/test DocumentRoot, but then all the websites point to the test directory.
My domain vhost file looks like this:
<VirtualHost *:80>
ServerName www.domain1.com
ServerAlias domain1.com
DirectoryIndex index.html index.php
DocumentRoot /home/user1/public/domain1.com/public
<Directory /home/user1/public/domain1.com/public>
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Order allow,deny
allow from all
</Directory>
</VirtualHost>
My testing one looks lithe this, but when enabled all the domains point to the test folder
<VirtualHost ex.ter.nal.ip>
ServerName ex.ter.nal.ip
DirectoryIndex index.html index.php
DocumentRoot /home/test/public
<Directory /home/test/public>
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Order allow,deny
allow from all
</Directory>
</VirtualHost>
Related
I have a curious situation: I would like to block the listing of files in a directory. Therefore I wanted to use a htaccess file. I am using an Apache webserver.
This is my configuration of my webserver:
<VirtualHost *:443>
DocumentRoot /var/www/html
<Directory /var/www/html>
AllowOverride All
</Directory>
ServerName www.example.com
<Directory /var/www/html/Files>
Options FollowSymLinks
# Options -Indexes
AllowOverride All
</Directory>
<Directory /var/www/html/Files/admin>
AllowOverride All
</Directory>
In the admin directory there is a .htaccess file with this content:
Options -Indexes
I also restarted Apache without any effect. Apache runs without an error, but the directory still listens the files. The URL for the directory is https://example.com/Files/admin
Do you have any idea why it might not work? I have read that AllowOverride is required. And this seems to be the case.
I got the solution. I needed to change the file /etc/apache2/apache2.conf and than it worked well.
i just want to run 2 web applications which both are in seperate subfolders.
So Subfolder One (which is the Homepage) should be reachable under : example.com.
While Subfolder two should be reachable under example.com/subfolder .
I know it is somehow possible with the Apache vhosts file, but i am new to this vhost stuff und dont know, how to solve that problem.
Thanks for your help!
i just got it running like that! Is there any reason this could be a problem in sight of security?
<VirtualHost *:80>
ServerName example.com
ServerAdmin example#mail.com
Redirect permanent / https://example.com
DocumentRoot /var/www/webpage/
<Directory /var/www/webpage/>
</Directory>
</VirtualHost>
**And for SSL**
<VirtualHost *:443>
ServerAdmin example#mail.com
ServerName example.com:443
<IfModule mod_headers.c>
Header always set Strict-Transport-Security "max-age=15552000; includeSubDomains"
</IfModule>
DocumentRoot /var/www/webpage/
<Directory /var/www/webpage/>
Options FollowSymLinks
AllowOverride All
</Directory>
<Directory /var/www/webpage>
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Order allow,deny
allow from all
</Directory>
Alias /subfolder /var/www/subfolder/
<Directory /var/www/subfolder>
Order allow,deny
allow from all
</Directory>
SSLCertificateFile /etc/certs/live/**********/fullchain.pem
SSLCertificateKeyFile /etc/certs/live/**********/privkey.pem
Include /etc/letsencrypt/options-ssl-apache.conf
</VirtualHost>
I want to subdomain use different folder. For example: example.com use /var/www/example and blog.example.com use /var/www/exampleblog.
Right now if I go to example.com or www.example.com the website loads correctly, but if I go to blog.example.com I got DNS_PROBE_FINISHED_NXDOMAIN.
The virtualhost files:
example.conf
<VirtualHost *:80>
DocumentRoot /var/www/example/
ServerName example.com
ServerAlias www.example.com
<Directory "/var/www/example/">
AllowOverride All
Options FollowSymLinks
</Directory>
ErrorLog /var/log/apache2/example-error
</VirtualHost>
And:
exampleblog.conf
<VirtualHost *:80>
DocumentRoot /var/www/exampleblog
ServerName blog.example.com
<Directory "/var/www/exampleblog/">
AllowOverride All
Options FollowSymLinks
</Directory>
ErrorLog /var/log/apache2/exampleblog-error
</VirtualHost>
What did I incorrectly?
The error was: The domain registrar isn't sent out the new settings when I wrote the question. They wrote, that it will be about 15-20 minutes, but somewhy it took more time.
I'm learning symfony right now. I want to use apache webserver instead of the shipped php. How can I add a virtualhost if I want to use also the default localhost? (localhost:80 for my notebook and I have a "personalhomepage")
Here is one of the vHosts I am currently using (cronolog is used for log rotation):
<VirtualHost *:80>
ServerName projectname.dev
DocumentRoot /var/www/projectname/html/web
<Directory /var/www/projectname/html/web>
Options Indexes FollowSymLinks
AllowOverride All
Require all granted
</Directory>
ErrorLog "|/usr/bin/cronolog /var/www/projectname/log/%Y-%m/error_%d_%m_%Y.log"
CustomLog "|/usr/bin/cronolog /var/www/projectname/log/%Y-%m/access_%d_%m_%Y.log" combined
</VirtualHost>
For testing and development purposes I usually create a local domain with the .dev or .local ending in the hosts file, e.g.:
127.0.0.1 projectname.dev
Make sure the domain name corresponds with the one in the vHost config. Oh, and don't dont forget to restart apache. Hope this helps.
Using these steps, you can use either projectname.dev, projectname.dev/app_dev.php or you set the vHost's DirectoryIndex directly, if you want to always use app_dev.php:
<Directory /var/www/projectname/html/web>
Options Indexes FollowSymLinks
AllowOverride All
Require all granted
DirectoryIndex app_dev.php
</Directory>
You would setup Apache in the same way as any other webservers that have more than one site on them - ideally, a named vhost. Symfony has an example Apache vhost config,
<VirtualHost *:80>
ServerName domain.tld
ServerAlias www.domain.tld
ServerAlias www.sitename.127.1.0.1.xip.name
DocumentRoot /var/www/project/web
<Directory /var/www/project/web>
AllowOverride None
Order Allow,Deny
Allow from All
<IfModule mod_rewrite.c>
Options -MultiViews
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ app.php [QSA,L]
# In local development, I default this to app_dev.php
</IfModule>
</Directory>
ErrorLog /var/log/apache2/project_error.log
CustomLog /var/log/apache2/project_access.log combined
</VirtualHost>
In this example, domain.tld (or www.) is the name you would use to reach the site. You would have to be able to reach those names via DNS though - on your local machine, 127.0.0.1. There are also some 'wildcard DNS' services that may help, such as http://xip.name/ With services such as these, you could put ServerName sitename.127.1.0.1.xip.name into the above configuration and then use that to reach your site.
I do something similar myself with a wildcard DNS sub-domain I own for a local machine. I have a number of such Apache Vhost configurations setup.
I recently created a virtual host with WampServer (Version 2.4) so I can access my local website with the url http://yannbergonzat.local :
<VirtualHost *>
ServerName yannbergonzat.local
DocumentRoot "F:\Projets\Web\yann"
DirectoryIndex index.php
</VirtualHost>
And here is the Directory tag from httpd.conf :
<Directory />
Options Indexes FollowSymLinks
AllowOverride all
Require all granted
</Directory>
This website is made with Symfony2, so yannbergonzat.local leads to a folder. If you want to access the actual website, you have to go to yannbergonzat.local/web/app.php .
I created a .htaccess file so the website can be seen with yannbergonzat.local :
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ web/$1 [QSA,L]
</IfModule>
And now is the problem. Depending on the value of AllowOverride, there are errors.
When AllowOverride is set on "all"
The .htaccess file is read, the site can be accessed on yannbergonzat.local, but the resources (stylesheets, javascripts) which are in another folder cannot be accessed (error 403)
When AllowOverride is set on "none"
The .htaccess file is not read, the site can not be accessed on yannbergonzat.local (it shows the content of the folder), you have to write the entire url (yannbergonzat.local/web/app.php), but the resources (stylesheets, javascripts) which are in another folder can be accessed.
What should I do to have the website on yannbergonzat.local with the resources from other folders working fine ?
This change to httpd.conf is VERY DANGEROUS
<Directory />
Options Indexes FollowSymLinks
AllowOverride all
Require all granted
</Directory>
as it allows all access to the whole of the drive you installed WampServer( Apache ) onto, if thats the C:\ drive you are making a hackers life very easy!
You should change httpd.conf that back to
<Directory />
Options FollowSymLinks
AllowOverride None
Require all denied
</Directory>
And add the directory specification to your VHOST definition like this
<VirtualHost *:80>
ServerName yannbergonzat.local
DocumentRoot "F:\Projets\Web\yann"
DirectoryIndex index.php
<Directory "F:\Projets\Web\yann">
Options Indexes FollowSymLinks
AllowOverride all
Require all granted
</Directory>
</VirtualHost>
AllowOverride none is an instruction to Apache to ignore any .htaccess files, so that explains what you have described.
When setting up a Symfony2 site this is the recommended config for a Virtual Host setup. You specify the /web folder as the DocumentRoot
See documentation
So I am assuming (you dont specify the actual folder structure) you would need something like this:
<VirtualHost *:80>
ServerName yannbergonzat.local
DocumentRoot "F:/Projets/Web/yann/web"
DirectoryIndex index.php
<Directory "F:/Projets/Web/yann/web">
# enable the .htaccess rewrites
AllowOverride All
Require all granted
</Directory>
</VirtualHost>
This will almost definitely fix your 403 error as you are now granting access Require all granted to the folder that the site actually exists in.
This code worked for me:
sudo chmod -R 755 /var/www/***
Makes sure SELinux is not in not blocking access to your web directory:
chcon -R -u system_u -t httpd_sys_content_t /home/user/www