Different website through domain - html

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.

Related

First try setting up Apache Reverse Proxy - css and images not being found

I am trying to put a working web site server behind a reverse proxy - both using Apache.
Server1 (10.27.27.60) (in a VM) has six different web sites configured using VirtualHost files structured like
<VirtualHost *:80>
ServerName www.mydomain1.org
ServerAlias mydomain1.org
DocumentRoot /var/www/mydomain1.org/html
ErrorLog /var/www/mydomain1.org/log/error.log
CustomLog /var/www/mydomain1.org/log/requests.log combined
</VirtualHost>
I have set up a new VM Apache server r-proxy1 (10.27.27.66) and set it up to proxy just a single domain. My router forwards port 80 to r-proxy1.
I must have looked at 10+ sites on how to do it and there was minimal consistency - so it was impossible to know for sure what was essential or not. Eventually I came up with:
<VirtualHost *:80>
ServerName example.org
ServerAlias example.*
ProxyRequests Off
SSLProxyEngine on
ProxyPreserveHost On
CustomLog /var/www/logs/AccessLog.log combined
ErrorLog /var/www/logs/ErrorLog.log
TransferLog /var/www/logs/TransferLog.log
ProxyPass / http://10.27.27.60
ProxyPassReverse / http://10.27.27.60
</VirtualHost>
The site now appears but the css, images and js files are not being found. The folders for these files are in subfolders in the html folder and are all referenced in the html like './css/style.css'.
Chrome is showing errors like: GET http://example.org/css/style.css net::ERR_ABORTED 502 (Proxy Error)
I have tried moving the css etc. files to the root html folder and changing the html reference and the files are still not found (GET http://example.org/style.css net::ERR_ABORTED 502 (Proxy Error))
I have tried adding a / at the end of the ProxyPass lines and have tried adding additional lines like
ProxyPass /css/ http://10.27.27.60/css/
ProxyPassReverse /css http://10.27.27.60/css/
into the VirtualHost file but the errors remain. My problem seems to be common but none of the suggestions I have found have helped.
What am doing wrong?

Creating subdomains / virtualhost in apache on CentOS

I used to access my website directly like so:
100.100.100.100/project1/public
I was also using an edit tool and accessing it like so:
100.100.100.100/tool
I added a subdomain (dev.domain.com) to my A records and updated my apache httpd.conf file like so:
NameVirtualHost *:80
<VirtualHost *:80>
ServerName www.dev.domain.com
ServerAlias dev.domain.com
ServerAdmin email#domail.com
DocumentRoot /var/www/html/project1/public
</VirtualHost>
and now I can access my website directly by typing my subdomain: - dev.domain.com.
But since I did that, I cannot access my edit tool the way I used too (100.100.100.100/tool) anymore. It looks like apache is trying to access my website (project1) when I type 100.100.100.100/tool
Is there a way to setup my subdomain so it only access my website located at /var/www/html/project1/public without affecting any other documents I have under /var/www/html/ ??? without affecting, e.g.:
/var/www/html/tool
/var/www/html/project2
/var/www/html/project3
I typed in the following command and got:
# apachectl -t -D DUMP_VHOSTS
httpd: Could not reliably determine the server's fully qualified domain name, using 100.100.100.100 for ServerName
VirtualHost configuration:
wildcard NameVirtualHosts and _default_ servers:
*:80 www.dev.domain.com (/etc/httpd/conf/httpd.conf:1021)
Syntax OK

Redirect HTML "/" to subfolder of WWW directory, the VirtualHost DocumentRoot

Sorry for asking this question again. Even though this has been asked and discussed quite a bit I cannot seem to find the right solution for a local dev environment using VirtualHost. I am using XAMPP Portable for Windows for dev work but assume this is the same for any other local server with regards to the .htaccess file.
DocumentRoot of VirtualHost is D:\dev\www\ for example.
ServerName is devwork.webdev for example.
HOSTS entry is 127.0.0.1 devwork.webdev.
VirtualHost file does have a default DocumentRoot being DocumentRoot "D:/xampp/htdocs". It works just fine.
The projects are each in a folder under D:\dev\www\ for example D:\dev\www\project01\ or D:\dev\www\project02\ and so on and show nicely in the browser when going to devwork.webdev with Options Indexes FollowSymLinks enabled. Apache is not showing any error and the access log file is also OK, things are working.
Now in my HTML when I use Project 01 a click on the link does link me to D:\dev\www\ showing all the projects I have in that folder.
Instead I would like to be linked to the root of the project, being D:\dev\www\project01\ or rather http://devwork.webdev/project01/.
How can I get that to work?
I am looking for a solution to this so that I can do dev work locally and without changing the HTML later FTP the data to the live host's root and it will work.
I have read and tried the following:
http://coolestguidesontheplanet.com/redirecting-a-web-folder-directory-to-another-in-htaccess/
https://perishablepress.com/redirect-subdirectory-to-root-via-htaccess/ .htaccess How to redirect root URL to subdirectory files, rewrite to clean URL AND not affect subdomains?
http://alexcican.com/post/how-to-remove-php-html-htm-extensions-with-htaccess/
https://stackoverflow.com/a/990405/1010918
How to redirect /directory/index.html and /directory/index.php to /directory/
Redirecting /directory/index.html to /directory/
with
How to remove .html from URL
and
http://forums.modx.com/thread/77211/endless-friendly-url-redirect-from-subdomain-folder-location
being closest to what I think I need but I must be doing something wrong since I always arrive at the DocumentRoot instead of the folder where the project is kept under the DocumentRoot.
Thank you for any help.
This seems closest:
Add VirtualHost definition for each project you want to access. (I'm
not sure how to do it on XAMPP for Windows).
For example, project01.devwork.webdev...
Set DocumentRoot for this VirtualHost to D:\dev\www\project01...
Add the hostname to your /etc/hosts/ file.
Open http://project01.devwork.webdev/ in your browser.
You should see the application in D:\dev\www\project01, while all URLs
will be based on "/".
What happens in the background:
When you open the URL http://project01.devwork.webdev/ in your browser, it will (as usual) translate it to IP address, but along with the request, it will also send Host header with the entered hostname:
GET / HTTP/1.1
Host: project01.devwork.webdev
Based on the Host field, Apache will decide which VirtualHost it needs to "pretend" to be, and serve files from the respective direcory.
However, if you need to have index of the projects, you will have to create it manually with full URLs.
An alternative with the given logic would be to simply add a VirtualHost for each project in D:dev\www\projectname by giving it its own domain instead of a subdomain on the host.
There is little difference there now when already editing httpd-vhosts.conf (using XAMP this file is in InstallDir and then in apache\conf\extra )but ideally it makes copying the local HTML to the live server without changing the HTML possible.
So this is something devs doing local work should keep in mind. I certainly will!! Thank you for your help and information.
<VirtualHost *:80>
DocumentRoot "D:/dev/www/newprojectname"
ServerName newdomainname.webdev
ServerAlias www.newdomainname.webdev
ErrorLog "D:/dev/www/log/dev-apache.error.log"
CustomLog "D:/dev/www/log/dev-apache.access.log" common
<Directory "D:/dev/www/newprojectname">
AllowOverride All
Options Indexes FollowSymLinks
Require local
# more detailed local
# Require ip 192.168.188
# or the IP from your local network
</Directory>
</VirtualHost>

Two XAMPP WordPress Installations, pointing one to a different URL, both not working correctly

I am running Windows 7 with an XAMPP local server with an installation of WordPress. I know this one works correctly, I've used it many times. I have a MySQL database for it and it sits in htdocs/wordpress.
Now, I have a contract in which I'm working for someone on another WordPress theme and would like to have this as a separate database and install. So, I make another folder in htdocs, let's call it folder2. I then create another database in MySQL, import the db I was given, and create a user to match the wp-config.php file of this install. No problem, except that it points to "localhost/folder2" and I need it to point to "local.folder2.com" to match the contractor.
So I hunt around the web and stumble on VirtualHosts for XAMPP. I go to /System32/drivers/etc/hosts and add the domain.
127.0.0.1 localhost ## Already here for XAMPP purposes
127.0.0.1 local.folder2.com ## URL to point localhost/folder2 towards
I then go to /xampp/apache/conf/extra/httpd-vhosts.conf and add the necessary Virtual Host.
NameVirtualHost *:80
<VirtualHost *:80>
DirectoryRoot "C:/xampp/htdocs/folder2"
ServerName local.folder2.com
</VirtualHost>
I restart Apache and MySQL. Problem is, now local.folder2.com works, but "localhost/wordpress/" does not. Using that URL directs me to the theme and db of folder2, baffling me entirely. Any ideas? I realize I can just work on one and not the other, but if I ever have more than one client at a time, switching it all out isn't going to work.
In this case, localhost stopped working because when another vhost was declared, no longer did the inherent connection between http://localhost.com and the directory "/htdocs" work. The solution was to add a vhost for the original location and then add a second one for the new location. Simple as:
<VirtualHost *:80>
ServerName localhost
DocumentRoot "C:/xampp/htdocs/wordpress" # Where I had localhost pointing
</VirtualHost>
<VirtualHost *:80>
ServerName local.folder2.com
DocumentRoot "C:/xampp/htdocs/folder2"
<Directory "C:/xampp/htdocs/folder2">
Allow Override All
</Directory>
</VirtualHost>
Of course, you then must add them to your hosts file:
127.0.0.1 localhost
127.0.0.1 local.folder2.com
Restart Apache server, and you're good to go.

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