How to add a second site in httpd.conf - apache

I'm using the following configuration of httpd.conf in my CentOs 7 Apache server to run "site1":
ServerRoot "/etc/httpd"
Listen 80
Include conf.modules.d/*.conf
User apache
Group apache
ServerAdmin root#localhost
ServerName locahost:80
<Directory />
AllowOverride none
Require all denied
</Directory>
DocumentRoot "/var/www/html/site1"
<Directory "/var/www">
AllowOverride None
# Allow open access:
Require all granted
</Directory>
<Directory "/var/www/html/site1">
Options FollowSymLinks
AllowOverride all
Order allow,deny
Allow from all
</Directory>
<IfModule dir_module>
DirectoryIndex index.html
</IfModule>
<Files ".ht*">
Require all denied
</Files>
ErrorLog "logs/error_log"
LogLevel warn
<IfModule log_config_module>
LogFormat "%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\"" combined
LogFormat "%h %l %u %t \"%r\" %>s %b" common
<IfModule logio_module>
LogFormat "%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\" %I %O" combinedio
</IfModule>
CustomLog "logs/access_log" combined
</IfModule>
<IfModule alias_module>
ScriptAlias /cgi-bin/ "/var/www/cgi-bin/"
</IfModule>
<Directory "/var/www/cgi-bin">
AllowOverride None
Options None
Require all granted
</Directory>
<IfModule mime_module>
TypesConfig /etc/mime.types
AddType application/x-compress .Z
AddType application/x-gzip .gz .tgz
AddType text/html .shtml
AddOutputFilter INCLUDES .shtml
</IfModule>
AddDefaultCharset UTF-8
<IfModule mime_magic_module>
MIMEMagicFile conf/magic
</IfModule>
EnableSendfile on
IncludeOptional conf.d/*.conf
When I access "http://localhost", site1 and its subpages/subfolders work correctly.
I want now to be able to display a second website: when accessing "http://localhost/site2", I want to display the content of a file "test.html" saved under "/test"; how should I edit the httpd.conf to make it work?

that's not a different site, it is a different directory. A different site would involve a different hostname.
Since you already have DocumentRoot "/var/www/html/site1 and you don't seem to want to create a new virtualhost you can point to a new/different directory with Alias
Also you just want site2 to load test.html under /test/ If I understood correctly when visited, just add the proper DirectoryIndex directive to it.
Here it is:
Alias /site2 /var/www/html/site2
<Directory /var/www/html/site2>
DirectoryIndex /test/test.html
</Directory>
For this to work you need these two modules:
mod_alias
mod_dir (but you may already have this one as you are already using DirectoryIndex directive)
You could also mkdir site2 under site1 but, this may look cleaner.

Related

apache2 disable redirect to https

My subdomain return me to https when I logout from my drupal website
I have tried to disable ssl and restart apache2 but not working
I have tried also to modify .htaccess file but always KO
and this only happened with this subdomain , All others domains works fine
my subdomain conf file
<VirtualHost sub.domain.fr:80>
ServerAdmin webmaster#mydomain.fr
DocumentRoot /home/ubuntu/mydomain/public_html/app2.mydomain.fr
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
<Directory "/home/ubuntu/mydomain/public_html/app2.mydomain.fr">
AllowOverride All
Require all granted
</Directory>
</VirtualHost>
apache2.conf file
DefaultRuntimeDir ${APACHE_RUN_DIR}
PidFile ${APACHE_PID_FILE}
Timeout 300
KeepAlive On
MaxKeepAliveRequests 100
KeepAliveTimeout 5
User ${APACHE_RUN_USER}
Group ${APACHE_RUN_GROUP}
HostnameLookups Off
ErrorLog ${APACHE_LOG_DIR}/error.log
LogLevel warn
IncludeOptional mods-enabled/*.load
IncludeOptional mods-enabled/*.conf
Include ports.conf
<Directory />
Options Indexes FollowSymLinks Includes ExecCGI
AllowOverride All
Order deny,allow
Require all granted
</Directory>
<Directory /usr/share>
AllowOverride None
Require all granted
</Directory>
<Directory /var/www/>
Options Indexes FollowSymLinks
AllowOverride None
Require all granted
</Directory>
AccessFileName .htaccess
<FilesMatch "^\.ht">
Require all denied
</FilesMatch>
LogFormat "%v:%p %h %l %u %t \"%r\" %>s %O \"%{Referer}i\" \"%{User-Agent}i\"" vhost_combined
LogFormat "%h %l %u %t \"%r\" %>s %O \"%{Referer}i\" \"%{User-Agent}i\"" combined
LogFormat "%h %l %u %t \"%r\" %>s %O" common
LogFormat "%{Referer}i -> %U" referer
LogFormat "%{User-agent}i" agent
IncludeOptional conf-enabled/*.conf
IncludeOptional sites-enabled/*.conf
Include sites-enabled/
ports.conf file
# If you just change the port or add more ports here, you will likely also
# have to change the VirtualHost statement in
# /etc/apache2/sites-enabled/000-default.conf
Listen 80
Listen 8080
<IfModule ssl_module>
Listen 443
</IfModule>
<IfModule mod_gnutls.c>
Listen 443
</IfModule>
First of all, change your vhost config to:
<VirtualHost *:80>
ServerName sub.domain.fr
then make sure the redirect doesn't happen just because of your browser cache: always use and anonymous window or, even better, simulate the navigation using curl so you don't use any kind of cached response.

Why is my root directory accessible from apache?

I was playing around when I suddenly noticed that my browser could access my root directory just by typing "/" in the address. I checked the httpd.conf, it clearly states:
<Directory "/">
AllowOverride none
Require all denied
</Directory>
I am on Fedora 29 and this is my httpd.conf:
ServerRoot "/etc/httpd"
Listen 80
LimitRequestBody 5242880
Include conf.modules.d/*.conf
User apache
Group apache
ServerAdmin root#localhost
<Directory "/">
AllowOverride none
Require all denied
</Directory>
DocumentRoot "/var/www/html"
<Directory "/var/www">
LimitRequestBody 5242880
AllowOverride None
Require all granted
</Directory>
<Directory "/var/www/html">
LimitRequestBody 5242880
Options Indexes FollowSymLinks
AllowOverride None
Require all granted
</Directory>
<IfModule dir_module>
DirectoryIndex index.html
</IfModule>
<Files ".ht*">
Require all denied
</Files>
ErrorLog "logs/error_log"
LogLevel warn
<IfModule log_config_module>
LogFormat "%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\"" combined
LogFormat "%h %l %u %t \"%r\" %>s %b" common
<IfModule logio_module>
# You need to enable mod_logio.c to use %I and %O
LogFormat "%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\" %I %O" combinedio
</IfModule>
CustomLog "logs/access_log" combined
</IfModule>
<IfModule alias_module>
ScriptAlias /cgi-bin/ "/var/www/cgi-bin/"
</IfModule>
<Directory "/var/www/cgi-bin">
LimitRequestBody 5242880
AllowOverride None
Options +ExecCGI
Require all granted
SetHandler fcgid-script
</Directory>
<IfModule mime_module>
TypesConfig /etc/mime.types
AddType application/x-compress .Z
AddType application/x-gzip .gz .tgz
AddType text/html .shtml
AddOutputFilter INCLUDES .shtml
</IfModule>
AddDefaultCharset UTF-8
<IfModule mime_magic_module>
MIMEMagicFile conf/magic
</IfModule>
EnableSendfile on
IncludeOptional conf.d/*.conf
LimitRequestBody 1024000
<Directory "/var/www/cgi-bin/data">
Order Deny,Allow
Deny From All
Allow From 127.0.0.1
</Directory>
Why is this happening?
My root directory was not accessed by apache. It was file uri parameters.

Apache does not execute .fcg file

I made the most basic fastcgi program using fastcgipp. I copied it into the /var/www/cgi-bin. I then went to /etc/httpd/conf/httpd.conf.
I replaced:
<Directory "/var/www/cgi-bin">
AllowOverride None
Options None
Require all granted
</Directory>
with this:
<Directory "/var/www/cgi-bin">
AllowOverride None
Options +ExecCGI
Require all granted
SetHandler fastcgi-script
</Directory>
But when I go to localhost/cgi-bin/index.fcg, the browser prompts me to download the fcg file instead of executing it.
I am using Fedora 29.
EDIT: This is the httpd.conf
ServerRoot "/etc/httpd"
Listen 127.0.0.1:80
Include conf.modules.d/*.conf
User apache
Group apache
ServerAdmin root#localhost
<Directory />
AllowOverride none
Require all denied
</Directory>
DocumentRoot "/var/www/html"
<Directory "/var/www">
AllowOverride None
# Allow open access:
Require all granted
</Directory>
<Directory "/var/www/html">
Options Indexes FollowSymLinks
AllowOverride None
Require all granted
</Directory>
<IfModule dir_module>
DirectoryIndex index.html
</IfModule>
<Files ".ht*">
Require all denied
</Files>
ErrorLog "logs/error_log"
LogLevel warn
<IfModule log_config_module>
LogFormat "%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\"" combined
LogFormat "%h %l %u %t \"%r\" %>s %b" common
<IfModule logio_module>
# You need to enable mod_logio.c to use %I and %O
LogFormat "%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\" %I %O" combinedio
</IfModule>
CustomLog "logs/access_log" combined
</IfModule>
<IfModule alias_module>
ScriptAlias /cgi-bin/ "/var/www/cgi-bin/"
</IfModule>
#
<Directory "/var/www/cgi-bin">
#AllowOverride None
Options +ExecCGI
#Require all granted
Order allow,deny
Allow from all
SetHandler fcgid-script
</Directory>
<IfModule mime_module>
TypesConfig /etc/mime.types
AddType application/x-compress .Z
AddType application/x-gzip .gz .tgz
AddType text/html .shtml
AddOutputFilter INCLUDES .shtml
</IfModule>
AddDefaultCharset UTF-8
<IfModule mime_magic_module>
MIMEMagicFile conf/magic
</IfModule>
EnableSendfile on
IncludeOptional conf.d/*.conf
Edit: I somehow get apache to execute the script. But now, the server gives me a 500 internal error. So, I checked the error_log file. It says:
End of script output before headers
I checked my code. I had outputted the header. This is the main.cpp file:
#include <fstream>
#include <boost/date_time/posix_time/posix_time.hpp>
void error_log(const char* msg) {
static std::ofstream error;
if(!error.is_open()){
error.open("/tmp/errlog", std::ios_base::out | std::ios_base::app);
}
error << "[" << boost::posix_time::second_clock::local_time() << "]: " << msg << "\n";
}
#include <fastcgi++/request.hpp>
#include <fastcgi++/manager.hpp>
class HelloWorld : public Fastcgipp::Request<char> {
bool response() {
out << "Content:Type: text/html\r\n\r\n";
out << "<html><head><meta charset=\"utf-8\"></head><body>";
out << "<p>It works!!!!</p>";
out << "</body></html>";
err << "Hi log!";
return true;
}
};
int main() {
Fastcgipp::Manager<HelloWorld> manager;
manager.setupSignals();
manager.listen();
manager.start();
manager.join();
return 0;
}
1) Added SetHandler fcgid-script in the <Directory "/var/www/cgi-bin"> tag in httpd.conf
2) I made a typo in the header. Replaced Content:Type:text/html with Content-Type:text/html

Apache serving name-based virtual Host from server hostname (but shouldn't be)

I have an Apache httpd server (2.4.6) running on Centos, serving several Name-based virtual hosts. The fqdn / hostname of the server should be serving no content, but it redirects to one of the Name-based virtual hosts and I don't understand why, or how to stop it.
In the configs below, a request to http://host.mydomain.org/ is redirected to http://www.customer.co.uk/.
Any ideas as to why, and the right way to stop it appretiated.
My httpd.conf is:
ServerRoot "/etc/httpd"
Listen 80
Include conf.modules.d/*.conf
User apache
Group apache
ServerAdmin root#xxx.org
ServerName host.mydomain.org:80
<Directory />
AllowOverride none
Require all denied
</Directory>
DocumentRoot "/var/www/html"
<Directory "/var/www">
AllowOverride None
Require all denied
</Directory>
<Directory "/var/www/html">
Options None
AllowOverride None
Require all denied
</Directory>
<IfModule dir_module>
DirectoryIndex index.html
</IfModule>
<Files ".ht*">
Require all denied
</Files>
ErrorLog "logs/error_log"
LogLevel warn
<IfModule log_config_module>
LogFormat "%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\"" combined
LogFormat "%h %l %u %t \"%r\" %>s %b" common
<IfModule logio_module>
# You need to enable mod_logio.c to use %I and %O
LogFormat "%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\" %I %O" combinedio
</IfModule>
CustomLog "logs/access_log" combined
</IfModule>
<IfModule alias_module>
ScriptAlias /cgi-bin/ "/var/www/cgi-bin/"
</IfModule>
<Directory "/var/www/cgi-bin">
AllowOverride None
Options None
Require all denied
</Directory>
<IfModule mime_module>
TypesConfig /etc/mime.types
AddType application/x-compress .Z
AddType application/x-gzip .gz .tgz
AddHandler cgi-script .cgi
AddHandler cgi-script .pl
AddType text/html .shtml
AddOutputFilter INCLUDES .shtml
</IfModule>
AddDefaultCharset ISO-8859-1
<IfModule mime_magic_module>
MIMEMagicFile conf/magic
</IfModule>
EnableSendfile on
TraceEnable Off
ServerTokens Prod
IncludeOptional conf.d/*.conf
An example virtual host is:
<VirtualHost *:80>
DocumentRoot /home/xxx/customer/docs
ServerName www.customer.co.uk
ErrorLog /home/xxx/customer/logs/error_log
CustomLog /home/xxx/customer/logs/access_log combined
<Directory /home/xxx/customer/docs>
AllowOverride None
Options None
Require all granted
</Directory>
</VirtualHost>
<VirtualHost *:80>
ServerName customer.co.uk
Redirect permanent / http://www.customer.co.uk/
</VirtualHost>
<VirtualHost *:80>
ServerName www.customer.mydomain.org
Redirect permanent / http://www.customer.co.uk/
</VirtualHost>
Thanks very much
Kevin
The first VirtualHost in the configuration file has the highest priority and can be seen as the default or primary server. That means that if a request is received that does not match one of the specified ServerName or ServerAlias directives, it will be served by this first <VirtualHost>.
You can prevent this by adding this (for example) as the first VirtualHost:
<VirtualHost *:80>
ServerName default
RewriteEngine On
RewriteRule ^ - [F]
</VirtualHost>

WAMP page not displaying over internet

I am running my WAMP server on my laptop running Windows 8.
I have a site set up at /www/MySite and made some Changes to my httpd.conf file as to make it accessable on the web, I've opened port 8080 in my router, and I've changed the ports to 8080 in my config.
Here's what I can do: I can get the site to work on these addresses:
http://127.0.0.1:8080/ok4pgm/
http://localhost:8080/ok4pgm/
http://192.168.1.77:8080/ok4pgm/
the first addresses can't be used for obvious reasons, and I'm guessing the second can't be used either since the address to my router begins with 192.168 and I therefore suspect it's some kind of local thing.
My IP address seems to be 213.114.161.6 (WhatsMyIP.org, canyouseeme.org & no-ip client) but it won't work on http://213.114.161.6:8080/ok4pgm/ - not even if I momentarily disable my firewall (and no, canyouseeme can't see port 80 nor 8080)
my httpd.conf:
ServerSignature On
ServerTokens Full
ServerRoot "c:/wamp/bin/apache/apache2.4.9"
Define APACHE24 Apache2.4
Listen 0.0.0.0:8080
Listen [::0]:8080
LoadModule php5_module "c:/wamp/bin/php/php5.5.12/php5apache2_4.dll"
<IfModule unixd_module>
User daemon
Group daemon
</IfModule>
ServerAdmin admin#example.com
ServerName localhost:8080
HostnameLookups Off
DocumentRoot "c:/wamp/www/"
<Directory />
AllowOverride none
Require all granted
</Directory>
<Directory "c:/wamp/www/">
Options Indexes FollowSymLinks
AllowOverride all
Require all granted
</Directory>
<IfModule dir_module>
DirectoryIndex index.php index.php3 index.html index.htm
</IfModule>
<Files ".ht*">
Require all denied
</Files>
ErrorLog "c:/wamp/logs/apache_error.log"
LogLevel warn
<IfModule log_config_module>
LogFormat "%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\"" combined
LogFormat "%h %l %u %t \"%r\" %>s %b" common
<IfModule logio_module>
LogFormat "%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\" %I %O" combinedio
</IfModule>
CustomLog "c:/wamp/logs/access.log" common
</IfModule>
<IfModule alias_module>
ScriptAlias /cgi-bin/ "c:/wamp/bin/apache/apache2.4.9/cgi-bin/"
</IfModule>
<IfModule cgid_module>
</IfModule>
<Directory "c:/wamp/bin/apache/apache2.4.9/cgi-bin">
AllowOverride None
Options None
Require all granted
</Directory>
<IfModule mime_module>
TypesConfig conf/mime.types
AddEncoding x-compress .Z
AddEncoding x-gzip .gz .tgz
AddType application/x-compress .Z
AddType application/x-gzip .gz .tgz
AddType application/x-httpd-php .php
AddType application/x-httpd-php .php3
</IfModule>
EnableSendfile off
AcceptFilter http none
AcceptFilter https none
Include conf/extra/httpd-autoindex.conf
<IfModule proxy_html_module>
Include conf/extra/proxy-html.conf
</IfModule>
<IfModule ssl_module>
SSLRandomSeed startup builtin
SSLRandomSeed connect builtin
</IfModule>
Include "c:/wamp/alias/*"
please, please help.
Your router is a computer. When someone makes a request to your Internet facing IP address, they are making it to your router and not to your workstation.
As well as opening the port on your router, you also need to configure port forwarding so that the router will pass on the request to your workstation.