Apache multiple sites, one works, other doesn't - apache

I've tried everything on similar questions but no luck.
I'm getting "You don't have permission to access X on this server." on all requests.
I have two sites on the same IP, the apache config files are identical, the file permissions are identical, however, one works and the other doesn't.
The config file:
<VirtualHost x.x.xxx.xx:80>
ServerName site2.example.com
ServerAlias site2.example.com
Redirect / https://site2.example.com/
<IfModule mod_security2.c>
SecRuleEngine Off
</IfModule>
</VirtualHost>
<VirtualHost x.x.xxx.xx:443>
Protocols h2 http/1.1
ServerName site2.example.com
ServerAlias site2.example.com
ServerAdmin it#example.com
SetEnv ENVIRONMENT production
DocumentRoot /data/www/site2.example.com
<Directory /data/www/site2.example.com>
Options -Indexes +FollowSymLinks
AllowOverride All
AddOutputFilterByType DEFLATE text/html text/plain text/xml text/css text/javascript application/javascript
Require all granted
</Directory>
<IfModule mod_security2.c>
SecRuleEngine Off
</IfModule>
ErrorLog /var/log/apache2/site2_error.log
LogLevel warn
KeepAlive On
SSLEngine On
SSLCertificateFile /etc/letsencrypt/live/site2.example.com/fullchain.pem
SSLCertificateKeyFile /etc/letsencrypt/live/site2.example.com/privkey.pem
Include /etc/letsencrypt/options-ssl-apache.conf
Header add Strict-Transport-Security "max-age=15768000"
# Add File Caching
<filesMatch ".(js|css|png|jpeg|jpg|gif|ico|pdf)$">
Header set Cache-Control "max-age=31536000, public"
</filesMatch>
# Disable slower encryption on older versions of IE
SetEnvIf User-Agent ".*MSIE [1-5].*" \
nokeepalive ssl-unclean-shutdown \
downgrade-1.0 force-response-1.0
SetEnvIf User-Agent ".*MSIE [6-9].*" \
ssl-unclean-shutdown
</VirtualHost>
What could I be missing?
The permission commands used:
sudo chown -R www-data:www-data /data/www/site2.example.com
sudo find /data/www/site2.example.com -type f -exec chmod 644 {} \;
sudo find /data/www/site2.example.com -type d -exec chmod 775 {} \;
I've already restarted apache.

So the problem was that for SSL the config file above wasn't being used. I've found the problem by listing the sites enabled sudo apache2ctl -S which returned:
port 443 namevhost site2.example.com (/etc/apache2/sites-enabled/site2-le-ssl.conf:2)
Which is a file created when setting up letsencrypt. I fixed the issue by disabling the config file, sudo a2dissite site2-le-ssl.conf.

Maybe the problem is not the config. Many other modifiers (including .htaccess) impact the server response.
To isolate the problem, use the failing website config file but use the working website directory path and see if it works.

Related

Centos You don't have permission

So my im having difficulties with a website server. When i try to access it, i get the error "You don't have permission to access /index.html on this server."
However i've given rights to the folders and the files exactly as ive done with a different server that does the same thing. Only way ive found to get rid of the error is with a command :
chcon -R -t httpd_sys_content_t /var/www/html/
However the solution is not permanent, it seems to go away each time i use a jenkins build on the server.
<VirtualHost *:80>
Redirect / servername
</Virtualhost>
<Virtualhost _default_:80>
ServerName localhost
<Location "/server-status">
Require all granted
SetHandler server-status
Order Allow,Deny
Allow from ::1
Allow from 127.0.0.1
Allow from 192.168****/23
Allow from 192.168****
</Location>
ErrorLog logs/error.log
SetEnvIf Remote_Addr "::1" dontlog
SetEnvIf User-Agent ".*internal dummy connection.*" dontlog
CustomLog /var/log/httpd/access.log combined env=!dontlog
</VirtualHost>
Problem diverted.
I managed to solve this by editing /etc/selinux/config file in Centos 7 and turn selinux disabled. Reboot and problem went away for good.

403 errors for images only on newly added ServerAlias

I have had two webservers running on the same machine with addresses like the following:
internal.myservername.com
and
test.myservername.com
The test site is (on some pages) pulling images from the internal site, and works flawlessly. Now that we are out of testing, I wanted to add/change the test domain to be the main site, so I added the apache server alias of myservername.com to the test site, but although all pages work, any images from internal will not show up on that address, resulting in a 403 error:
[access_compat:error] AH01797: client denied by server configuration
I have also tried setting up myservername.com as its own domain, and also tried making it the primary name on the test site (with test being an alias). In all cases, test.myservername.com continues to work fine and display images correctly, whereas myservername.com will not (resulting in all the 403 errors for these embedded images).
I have checked all configs and find nothing amiss. And there is nothing in my .htaccess files or conf files that is specific to "test". I am stumped.
I should probably also mention that I am running on a Mac OS Sierra server. (Server version: Apache/2.4.23 (Unix))
UPDATE WITH REQUESTED DETAIL:
img tags: there is nothing special in the image tags, they are called using the full url, ie
<img src="http://internal.myservername.com/images/imagename.jpg" />
I should also add that if I take the exact src url and paste it alone into a browser, the image WILL load. It is only embedded in the page that it will refuse to load. (and only on the main domain, test works fine embedded in img tag)
And the setup of test/main conf is:
<VirtualHost 127.0.0.1:34580>
ServerName http://test.myservername.com:80
ServerAdmin admin#example.com
DocumentRoot "/Library/Server/Web/Data/Sites/myservername.com/plugins/mywebsite"
DirectoryIndex index.php home.php index.html
CustomLog /var/log/apache2/access_log combinedvhost
ErrorLog /var/log/apache2/error_log
<IfModule mod_ssl.c>
SSLEngine Off
SSLCipherSuite "HIGH:MEDIUM:!MD5:!RC4:!3DES"
SSLProtocol -all +TLSv1 +TLSv1.1 +TLSv1.2
SSLProxyEngine Off
SSLProxyProtocol -all +TLSv1 +TLSv1.1 +TLSv1.2
</IfModule>
<IfModule mod_secure_transport.c>
MSTEngine Off
MSTCipherSuite HIGH, MEDIUM
MSTProtocolRange TLSv1.2 TLSv1.2
MSTProxyEngine On
MSTProxyProtocolRange TLSv1.2 TLSv1.2
</IfModule>
<Directory "/Library/Server/Web/Data/Sites/myservername.com/plugins/mywebsite">
Options All -Indexes +ExecCGI +Includes +MultiViews
AllowOverride All
<IfModule mod_dav.c>
DAV Off
</IfModule>
<IfDefine !WEBSERVICE_ON>
Require all denied
ErrorDocument 403 /customerror/websitesoff403.html
</IfDefine>
</Directory>
ServerAlias myservername.com
And the conf for internal:
<VirtualHost 127.0.0.1:34580>
ServerName http://internal.myservername.com:80
ServerAdmin admin#example.com
DocumentRoot "/Library/Server/Web/Data/Sites/myservername.com"
DirectoryIndex index.php
CustomLog /var/log/apache2/access_log combinedvhost
ErrorLog /var/log/apache2/error_log
<IfModule mod_ssl.c>
SSLEngine Off
SSLCipherSuite "HIGH:MEDIUM:!MD5:!RC4:!3DES"
SSLProtocol -all +TLSv1 +TLSv1.1 +TLSv1.2
SSLProxyEngine Off
SSLProxyProtocol -all +TLSv1 +TLSv1.1 +TLSv1.2
</IfModule>
<IfModule mod_secure_transport.c>
MSTEngine Off
MSTCipherSuite HIGH, MEDIUM
MSTProtocolRange TLSv1.2 TLSv1.2
MSTProxyEngine On
MSTProxyProtocolRange TLSv1.2 TLSv1.2
</IfModule>
<IfModule mod_headers.c>
<filesmatch "^.*www.*\.jpg$">
Header set Cache-Control "max-age=2678400, public"
</filesmatch>
</IfModule>
<Directory "/Library/Server/Web/Data/Sites/myservername.com">
Options All -Indexes +ExecCGI +Includes +MultiViews
AllowOverride All
Require all granted
<IfModule mod_dav.c>
DAV Off
</IfModule>
<IfDefine !WEBSERVICE_ON>
Require all denied
ErrorDocument 403 /customerror/websitesoff403.html
</IfDefine>
</Directory>
</VirtualHost>
UGH, I just figured out what was causing this, and here are the steps I took to figure it out:
Because my error was happening in mod_access_compat, I turned off that module to see if anything changed
This resulted in a much more clear error_log message that pointed to a problem with an .htaccess file inside my images folder on the internal site (that was setup by someone else and that I had no idea existed until the error showed it to me)
That .htaccess file contained directives that allowed my test site to pull images, but not the new domain, so once I added it to the file, all was fixed.
For those that want to know what the directives there were:
SetEnvIfNoCase Referer "^http://test.myservername.com/" locally_linked=1
SetEnvIfNoCase Referer "^http://test.myservername.com$" locally_linked=1
SetEnvIfNoCase Referer "^http://internal.myservername.com/" locally_linked=1
SetEnvIfNoCase Referer "^http://internal.myservername.com$" locally_linked=1
SetEnvIfNoCase Referer "^$" locally_linked=1
<FilesMatch "\.(gif|png|jpe?g)$">
Order Allow,Deny
Allow from env=locally_linked
</FilesMatch>
And by adding the following two lines, it now works:
SetEnvIfNoCase Referer "^http://myservername.com/" locally_linked=1
SetEnvIfNoCase Referer "^http://myservername.com$" locally_linked=1

.htaccess being ignored - Ubuntu 14.04

I'm trying to use the .htaccess file on my Apache server.
Here is what my .htaccess looks like
# 1 YEAR
<FilesMatch "\.(ico|svg|woff|eot|ttf)$">
Header set Cache-Control "max-age=31536000, public"
</FilesMatch>
# 1 WEEK
<FilesMatch "\.(jpg|png|gif|css|js)$">
Header set Cache-Control "max-age=604800, public"
</FilesMatch>
# Add correct content-type for fonts
AddType application/vnd.ms-fontobject .eot
AddType font/ttf .ttf
AddType font/otf .otf
AddType font/x-woff .woff
AddType image/svg+xml .svg
# Compress compressible fonts
AddOutputFilterByType DEFLATE font/ttf font/otf image/svg+xml
I enabled mod_rewrite using a2enmod rewrite
The tutorials I followed told me to edit the file in /etc/apache2/sites-available/default but there isn't a file by the name default in that folder. There was a 000-default.conf instead in the same path. But that file didn't have the part
<Directory /var/www/>
Options Indexes FollowSymLinks
AllowOverride None
Require all granted
</Directory>
which I'm supposed to edit.
This is the contents of 000-default.conf
<VirtualHost *:80>
# The ServerName directive sets the request scheme, hostname and port that
# the server uses to identify itself. This is used when creating
# redirection URLs. In the context of virtual hosts, the ServerName
# specifies what hostname must appear in the request's Host: header to
# match this virtual host. For the default virtual host (this file) this
# value is not decisive as it is used as a last resort host regardless.
# However, you must set it for any further virtual host explicitly.
#ServerName www.example.com
ServerAdmin webmaster#localhost
# Available loglevels: trace8, ..., trace1, debug, info, notice, warn,
# error, crit, alert, emerg.
# It is also possible to configure the loglevel for particular
# modules, e.g.
#LogLevel info ssl:warn
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
# For most configuration files from conf-available/, which are
# enabled or disabled at a global level, it is possible to
# include a line for only one particular virtual host. For example the
# following line enables the CGI configuration for this host only
# after it has been globally disabled with "a2disconf".
#Include conf-available/serve-cgi-bin.conf
</VirtualHost>
# vim: syntax=apache ts=4 sw=4 sts=4 sr noet
However /etc/apache2/apache2.conf had the exact same part. So I replaced AllowOverride None over there to AllowOverride All. I restarted the server after that.
However the .htaccess file is still not being loaded. If I add gibberish to the .htaccess file everything still works fine meaning it didn't get loaded.
What did I miss here?
First of all, the name of the file doesn't really matters. 000-default.conf, while not really common seems good to me.
Modify your site configuration
There are 2 major things you have to consider when serving .htaccess files :
AccessFileName .htaccess
AllowOverride All
As said in the apache2 doc, you must declare AllowOverride in a Directory section. That's why it didn't work when setting it in main config file.
I'd advise you to just paste those 4 lines in /etc/apache2/000-default.conf inside the Virtualhost section and it should work:
<Directory /var/www/>
Options Indexes FollowSymLinks
AllowOverride All
</Directory>
(assuming your root directory is /var/www)
You don't have to set AccessFileName as default is .htaccess.
If it doesn't work and you have more than 1 file in /etc/apache2/sites-available
Apache might use another config thant 000-default.conf. Just check which of those are symlinked to /etc/apache2/sites-enabled. If there's still more than 1, you might want to disable every other enabled site just to be sure.
If it still doesn't work, just check file ownership & permissions.
The isssue was that I was placing the .htaccess file in /var/www/ while my DocumentRoot for my website was pointing to a different directory. Moving the .htaccess file to that folder solved the issue.

XAMPP: Connecting to localhost fix? [Persistent]

I just installed XAMPP Windows 1.8.2 in my computer. Port 80 is secured and in use by Apache there are no problems nor any port conflicts. I always open Xampp and start both Apache and MySQL Modules in the control panel. Both modules are running, Whenever I click on the Apache admin button it redirects me to the localhost page, It takes a while to load and then this error shows up.
If it's too small for you guys the error says: Network Error (tcp_error)
A communication error occurred: "Connection refused"
The Web Server may be down, too busy, or experiencing other problems preventing it from responding to requests. You may wish to try again at a later time.
For assistance, contact your network support team.
Another error shows up if i try with 127.0.0.1:
The localhost changes to 130.147.134.66 NOTE: I use a proxy network and the IP address is 130.147.134.251.
I have tried changing and updating the hosts file in the C:\Windows\System32\Drivers\Etc\hosts. but the problem still persists.
Keep that in mind I am new to using Xampp, and its been only a week since I started using phpMyAdmin and MySQL
My httpd-xampp.conf file:
#
# XAMPP settings
#
<IfModule env_module>
SetEnv MIBDIRS "C:/xampp/php/extras/mibs"
SetEnv MYSQL_HOME "\\xampp\\mysql\\bin"
SetEnv OPENSSL_CONF "C:/xampp/apache/bin/openssl.cnf"
SetEnv PHP_PEAR_SYSCONF_DIR "\\xampp\\php"
SetEnv PHPRC "\\xampp\\php"
SetEnv TMP "\\xampp\\tmp"
</IfModule>
#
# PHP-Module setup
#
LoadFile "C:/xampp/php/php5ts.dll"
LoadModule php5_module "C:/xampp/php/php5apache2_4.dll"
<FilesMatch "\.php$">
SetHandler application/x-httpd-php
</FilesMatch>
<FilesMatch "\.phps$">
SetHandler application/x-httpd-php-source
</FilesMatch>
#
# PHP-CGI setup
#
#<FilesMatch "\.php$">
# SetHandler application/x-httpd-php-cgi
#</FilesMatch>
#<IfModule actions_module>
# Action application/x-httpd-php-cgi "/php-cgi/php-cgi.exe"
#</IfModule>
<IfModule php5_module>
PHPINIDir "C:/xampp/php"
</IfModule>
<IfModule mime_module>
AddType text/html .php .phps
</IfModule>
ScriptAlias /php-cgi/ "C:/xampp/php/"
<Directory "C:/xampp/php">
AllowOverride None
Options None
Require all denied
<Files "php-cgi.exe">
Require all granted
</Files>
</Directory>
<Directory "C:/xampp/cgi-bin">
<FilesMatch "\.php$">
SetHandler cgi-script
</FilesMatch>
<FilesMatch "\.phps$">
SetHandler None
</FilesMatch>
</Directory>
<Directory "C:/xampp/htdocs/xampp">
<IfModule php5_module>
<Files "status.php">
php_admin_flag safe_mode off
</Files>
</IfModule>
AllowOverride AuthConfig
</Directory>
<IfModule alias_module>
Alias /security "C:/xampp/security/htdocs/"
<Directory "C:/xampp/security/htdocs">
<IfModule php5_module>
<Files "xamppsecurity.php">
php_admin_flag safe_mode off
</Files>
</IfModule>
Order deny,allow
Deny from all
Allow from localhost
</Directory>
Alias /licenses "C:/xampp/licenses/"
<Directory "C:/xampp/licenses">
Options +Indexes
<IfModule autoindex_color_module>
DirectoryIndexTextColor "#000000"
DirectoryIndexBGColor "#f8e8a0"
DirectoryIndexLinkColor "#bb3902"
DirectoryIndexVLinkColor "#bb3902"
DirectoryIndexALinkColor "#bb3902"
</IfModule>
Require all granted
</Directory>
Alias /phpmyadmin "C:/xampp/phpMyAdmin/"
<Directory "C:/xampp/phpMyAdmin">
AllowOverride AuthConfig
Order allow,deny
Allow from all
Require all granted
</Directory>
Alias /webalizer "C:/xampp/webalizer/"
<Directory "C:/xampp/webalizer">
<IfModule php5_module>
<Files "webalizer.php">
php_admin_flag safe_mode off
</Files>
</IfModule>
AllowOverride AuthConfig
Require all granted
</Directory>
</IfModule>
#
# New XAMPP security concept
#
<LocationMatch "^/(?i:(?:xampp|security|licenses|phpmyadmin|webalizer|server-status|server-info))">
Order deny,allow
Deny from all
Allow from ::1 127.0.0.0/8 \
fc00::/7 10.0.0.0/8 172.16.0.0/12 192.168.0.0/16 \
fe80::/10 169.254.0.0/16
ErrorDocument 403 /error/XAMPP_FORBIDDEN.html.var
</LocationMatch>
It's already giving you the answer.
Look at your second picture.
This setting can be configured in the file "httpd-xampp.conf"
How to "fix" this:
either: disable your proxy for local addresses
or:
1) open the file "\xampp\apache\conf\extra\httpd-xampp.conf" in a texteditor
2) replace "Allow from localhost" with "Allow from YOURLOCALIP" (2 times)
3) save the file
4) restart Apache
See http://www.apachefriends.org/f/viewtopic.php?t=32503#p131519 too
Edit:
It's in line 120-128:
<LocationMatch "^/(?i:(?:xampp|security|licenses|phpmyadmin|webalizer|server-status|server-info))">
Order deny,allow
Deny from all
Allow from ::1 127.0.0.0/8 \
fc00::/7 10.0.0.0/8 172.16.0.0/12 192.168.0.0/16 \
fe80::/10 169.254.0.0/16 \
YOURLOCALIP <--------------------------------------------------------------
ErrorDocument 403 /error/XAMPP_FORBIDDEN.html.var
</LocationMatch>
Your security configuration for XAMPP is specified in the LocationMatch as chill0r mentioned, on lines 120-128.
Your configuration is allowing from ::1 127.0.0.0/8 \, fc00::/7 10.0.0.0/8, 172.16.0.0/12, 192.168.0.0/16, and fe80::/10 169.254.0.0/16 which will never be matched since you're using a proxy AND it's denying everything. This is where the Order statement comes in. It tells your configuration to match against deny first then allow, so it will always deny since you have Deny all.
You need to change your configuration so that it doesn't deny everything and allows at least your own IP. Since it sounds like your running a local dev environment and not exposing it, you can consider removing all restrictions:
<LocationMatch "^/(?i:(?:xampp|security|licenses|phpmyadmin|webalizer|server-status|server-info))">
Allow from all
ErrorDocument 403 /error/XAMPP_FORBIDDEN.html.var
</LocationMatch>
If you do this, configure your firewall prevent port 80 access from outside your network (this can be done on your machine or router). Alternatively, you can configure it to work for an IP range using a partial IP that includes your proxy:
<LocationMatch "^/(?i:(?:xampp|security|licenses|phpmyadmin|webalizer|server-status|server-info))">
Order allow,deny
Deny from all
Allow from 130.147.134
ErrorDocument 403 /error/XAMPP_FORBIDDEN.html.var
</LocationMatch>
Notice that the Order changed from deny,allow to allow,deny so it will check against the allow statement first.
I also noticed that the two requests were for different paths, the first one is "/" and the second is "/xampp/" and the latter is the one that wasn't refused.
In your IfModule alias_module you should add an alias:
Alias "/" "C:/xampp/htdocs/xampp"
This will help you get off the ground, but you'll need to make sure to learn about the directives, specifically Alias and AliasMatch as your routing gets more complicated. Alternatively, you could just develop in the C:/xampp/htdocs/ directory instead of C:/xampp/htdocs/xampp.
Before starting the XAMPP server make sure that other running services are closed like Skype and other servers which is using the same port number.
I had the same problem, the solution is easier than other answers.
1) Install XAMPP in your pc, in this case, Windows 8.
2) Start > Administrative Tools > Services > Web Deployment Agent service and press STOP.
Usually Web Deployment uses port 80 which is the port used by XAMPP by default. If you stop that process and write localhost in your web browser you should be able to access phpmyadmin.
Hope it helps :)
Follow the below Steps
In XAMPP on the Apache Module ,Select Config button httpd.conf
Comment "Deny from all" in the following section,
<LocationMatch "^/(?i:(?:xampp|security|licenses|phpmyadmin|webalizer|server-status|server-info))">
Order deny,allow
#Deny from all
Allow from ::1 127.0.0.0/8 \
fc00::/7 10.0.0.0/8 172.16.0.0/12 192.168.0.0/16 \
fe80::/10 169.254.0.0/16
ErrorDocument 403 /error/XAMPP_FORBIDDEN.html.var
</LocationMatch>
Restart the XAMPP (Important Step)

Mono IOMAP case sensitivity

Having some problems installing BlogEngine.NET onto my CentOS mod_mono 2.8 (mono 2.8.1) box.
The BlogEngine.NET code references a folder named 'Bin'. On looking at the contents of the directory, there is a folder called 'bin' - the normal place for the compiled source to reside.
Renaming the folder to 'Bin' is not an option, as this will cause mono problems (it requires the folder to be called 'bin').
I came accross this: http://www.mono-project.com/IOMap
Which suggests that IOMap in Mono will make mono 'ignore' case sensitivity.
I added MONO_IOMAP=all to my env, from su, and it appears when I call env However, this doesn't seem to work - it is still case sensitive.
I then added MonoSetEnv MONO_IOMAP=all to my apache vhosts file for a specific subdomain, and this still doesn't work.
Any ideas what I am doing wrong? Am I being blind and not adding MONO_IOMAP=all to env for any other users than root?
Update: My hosts.conf for this site looks like:
<VirtualHost *:80>
ServerAdmin webmaster#host.net
DocumentRoot /home/host/www/host.net/blog
ServerName blog.host.net
ErrorLog /home/host/www/host.net/logs/blog.host.net-error.log
TransferLog /home/host/www/host.net/logs/blog.host.net-access.log
CustomLog /home/host/www/host.net/logs/blog.host.net-access_combined.log combined
DirectoryIndex index.html index.aspx
MonoServerPath blog.host.net "/usr/local/bin/mod-mono-server2"
MonoExecutablePath blog.host.net "/usr/local/bin/mono"
MonoDebug blog.host.net true
MonoSetEnv blog.host.net MONO_IOMAP=all
MonoApplications blog.host.net "/:/home/host/www/host.net/blog"
<Location "/">
Allow from all
Order allow,deny
MonoSetServerAlias blog.host.net
SetHandler mono
SetOutputFilter DEFLATE
SetEnvIfNoCase Request_URI "\.(?:gif|jpe?g|png)$" no-gzip dont-vary
</Location>
<IfModule mod_deflate.c>
AddOutputFilterByType DEFLATE text/html text/plain text/xml text/javascript
</IfModule>
</VirtualHost>
Try to set MonoSetEnv with server alias, for example my configuration of virtual host looks like this:
DocumentRoot /var/www/my.domain.com/
ServerName my.domain.com
MonoServerPath mydomaincom /usr/local/bin/mod-mono-server4
MonoSetEnv mydomaincom MONO_IOMAP=all
AddMonoApplications mydomaincom "/:/var/www/my.domain.com/"
<Location />
Allow from all
Order allow,deny
MonoSetServerAlias mydomaincom
SetHandler mono
SetOutputFilter DEFLATE
SetEnvIfNoCase Request_URI "\.(?:gif|jpe?g|png)$" no-gzip dont-vary
</Location>
<IfModule mod_deflate.c>
AddOutputFilterByType DEFLATE text/html text/plain text/xml text/javascript
</IfModule>
I was able to resolve this by simply adding MonoSetEnv MONO_IOMAP=all to my httpd.conf configuration file (usually located at /etc/apache2/httpd.conf).
MonoSetEnv MONO_IOMAP=all