Appache virtualhost and proxy - apache

I am trying to redirect a virtualhost to a spefcific ip, in A docker network in my case.
I am on a raspberrypi4 with archlinux.
So, here is my config file, but it do not work, this redirect in my default vhost in local :
<VirtualHost *:80>
#ServerAdmin webmaster#mysite.com
#DocumentRoot "/srv/http/mysite.com"
ServerName mysite.com
ServerAlias mysite.com
ErrorLog "/var/log/httpd/mysite.com-error_log"
CustomLog "/var/log/httpd/mysite.com-access_log" common
ProxyPreserveHost On
ProxyPass "/" "http://172.19.0.5/"
ProxyPassReverse "/" "http://172.19.0.5/"
# <Directory "/srv/http/http/mysite.com">
# Require all granted
# </Directory>
</VirtualHost>
does anybody can help me to fix that ?? :/

Related

Redirect Apache application to dot net core application

I have a server which uses a domain example.com. I am using apache to run this web server. I have also installed Dot Net core and published a Dot Net core app to /var/www/app location.
I a trying to access this application using example.com/api
This below is what I have tried in 000-default.conf
<VirtualHost *:80>
ServerAdmin root#example.com
ServerName example.com
ServerAlias www.example.com
DocumentRoot /var/www/html
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
the below is what I hvae added for the application
<VirtualHost *:80>
ServerName example.com/api
ProxyPreserveHost On
<Proxy *>
Order allow, deny
Allow from all
</Proxy>
ProxyPass / http://localhost:5000/
ProxyPassReverse / http://localhost:5000/
</VirtualHost>
I have also tried the below configuration.
<VirtualHost *:80>
ServerName example.com/api
redirect / http://localhost:5000/
</VirtualHost>
can someone please help me find what am I doing wrong and how to achieve this properly.
This is solved by enabling proxy and proxy_http using commands below.
a2enmod proxy
a2enmod proxy_http
Also configured the Proxy inside the virtual host as follows.
<VirtualHost *:80>
ServerAdmin root#example.com
ServerName example.com
ServerAlias www.example.com
DocumentRoot /var/www/html
#Below 3 lines worked
ProxyPreserveHost On
Proxypass "/api/" "http://localhost:5000/"
ProxyPassReverse "/api/" "http://localhost:5000/"
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>

How to make an redirectSSL in the vhost

I get slightly crazy :)
I have a domain example.com and I have a SSL certificate for www.example.com
The example.com refers to the IP address of the server (it is an EC2 instance).
In the vhost.conf of the Server I have the following entries
<VirtualHost *:80>
ServerName example.com
Redirect permanent / https://www.example.com/
</VirtualHost>
<VirtualHost _default_:443>
ServerName www.example.com
DocumentRoot /var/www/vhosts/example-wp
SSLEngine On
...
</VirtualHost>
I took the information from the apache wiki.
https://wiki.apache.org/httpd/RedirectSSL
Thanks for helping
Tristan
You already have the necessary directives listed to perform the redirect. You also need to tell the vhost file where your certificate and key for the certificate exist. You also need to say whether or not a directory the user browses to is to load SSL. Please see a full example configuration file below.
<VirtualHost *:80>
ServerName www.example.com
ServerAlias example.com
Redirect / https://www.example.com/
</VirtualHost>
<VirtualHost *:443>
ServerName www.example.com
ServerAlias example.com
ServerAdmin webmaster#local
DocumentRoot /path/to/web/content
DirectoryIndex index.php index.html
ErrorLog logs/error_log
CustomLog logs/access combined
SSLEngine on
SSLCipherSuite ALL:!ADH:!EXPORT56:RC4+RSA:+HIGH:+MEDIUM:+LOW:+SSLv2:+EXP:+eNULL
SSLCertificateFile /etc/apache2/ssl.crt/certfile.cer
SSLCertificateKeyFile /etc/apache2/ssl.key/keyfile.key
<Directory "/path/to/web/content/">
Options None
AllowOverride None
Order allow,deny
Allow from all
SSLRequireSSL
</Directory>
</VirtualHost>

Apache virtual proxy, do not redirect from root

I have the following in my vhosts.conf:
NameVirtualHost *:80
<VirtualHost *:80>
ServerName ci.myserver.com
ProxyRequests Off
ProxyPreserveHost On
ProxyPass / ajp://127.0.0.1:8009/
ProxyPassReverse / ajp://127.0.0.1:8009/
ProxyPassReverseCookiePath / /
</VirtualHost>
Now, when I visit my root (myserver.com) I get my Jenkins, as well as when I visit ci.myserver.com
How to I get not redirected to CI when I visit myserver.com, but only make it work for ci.myserver.com
Updated version
This resolved an issue.
<VirtualHost *:80>
ServerName ci.myserver.com
ProxyRequests Off
ProxyPreserveHost On
ProxyPass / ajp://127.0.0.1:8009/
ProxyPassReverse / ajp://127.0.0.1:8009/
ProxyPassReverseCookiePath / /
</VirtualHost>
<VirtualHost *:80>
ServerName myserver.com
DocumentRoot /
<Directory />
Require all granted
</Directory>
</VirtualHost>
You need to create another VirtualHost, otherwise hostnames that resolve the ip of your server will hit the default VirtualHost, which in your case is ci.myserver.com.
Add another to the file:
<VirtualHost *:80>
ServerName myserver.com
DocumentRoot /path/to/root
<Directory /path/to/root>
Order allow,deny
allow from all
</Directory>
</VirtualHost>

Try to add a VirtualHost

I have a web server with a website and i want to add another address for pre-production use.
Here the existant:
httpd.conf:
ServerAdmin support#toto.com
ServerName www.toto.com:80
DocumentRoot "/home/tutu/var/www/html"
modules/vhost.conf:
<VirtualHost *:80>
ServerAdmin support#toto.com
ServerName www.toto.com:80
DirectoryIndex index.php
ErrorLog /home/tutu/var/log/httpd/error-mod_log
LogLevel warn
CustomLog /home/tutu/var/log/httpd/access-mod_log common-cookie
<Location /server-status>
SetHandler server-status
Order deny,allow
Deny from all
Allow from 127.0.0.1
</Location>
</VirtualHost>
And I have tried to add another VirtualHost but the new address not working:
<VirtualHost *:80>
ServerAdmin support#toto.com
ServerName www2.toto.com:80
DirectoryIndex index.php
ErrorLog /home/tutu/var/log/httpd/error-www2_log
LogLevel warn
CustomLog /home/tutu/var/log/httpd/access-www2_log common-cookie
DocumentRoot "/home/tutu/var/www2/html"
</VirtualHost>
The address www2.toto.com is not working.
Have you an idea?
Thanks
Have you added www2.toto.com to DNS?
It's not added to public DNS yet. (But www.toto.com is)
"Not working" is not very specific. Do you get the default Apache web-page for that site or do you not reach the server? If it's the latter, DNS lookup is likely your real problem, not the Apache config.
The Apache-config looks good, but you should not need to specify :80 as the alias port.

Apache 2 VHost - www.domain.com works but domain.com goes to registrar

I am using the following VHOST:
<VirtualHost *:80>
#Basic setup
ServerAdmin administrator#mydomain.com
ServerName www.mydomain.com
ServerAlias mydomain.com
<Directory /home/mydomain/public_html/mydomain.com/mydomain/apache/>
Order deny,allow
Allow from all
</Directory>
LogLevel warn
ErrorLog /home/mydomain/public_html/mydomain.com/logs/apache_error.log
CustomLog /home/mydomain/public_html/mydomain.com/logs/apache_access.log combined
WSGIDaemonProcess mydomain.com user=www-data group=www-data threads=20 processes=2
WSGIProcessGroup mydomain.com
WSGIScriptAlias / /home/mydomain/public_html/mydomain.com/mydomain/apache/mydomain.wsgi
</VirtualHost>
It's working fine when I visit www.mydomain.com, but mydomain.com is taking me to my domain registrars holding page (I am using their nameservers for simplicity.) Is this a problem with my vhost file or something I need to configure with the registrar?
Add mydomain.com A record in DNS
Add www.mydomain.com as cname in DNS
In vhost configuration change the entry like this:
ServerName mydomain.com
ServerAlias www.mydomain.com
It will work.