Unable to configure SSL to httpd-vhosts.conf - server

I'm using the ubuntu 16.04 server & lampp server and I get this error XAMPP: Your /etc/hosts is not okay. I will fix it. when I uncomment this line #SSLEngine on
So far it is running fine in port 80 I want to add SSL to it
Please help me out.
My httpd-vhosts.conf file
<VirtualHost 127.0.0.4:443>
DocumentRoot "/opt/lampp/htdocs/example.com/public"
ServerName example.com
DirectoryIndex index.php
#SSLEngine on
#SSLCertificateFile /etc/letsencrypt/live/example.com/privkey.pem
#SSLCertificateKeyFile /etc/letsencrypt/live/example.com/cert.pem
#SSLCertificateChainFile /etc/letsencrypt/live/example.com/chain.pem
<Directory "/opt/lampp/htdocs/example.com/public">
Options All
AllowOverride All
Require all granted
</Directory>
</VirtualHost>
My /etc/hosts file
127.0.0.1 localhost
127.0.0.4 example.com
# The following lines are desirable for IPv6 capable hosts
::1 ip6-localhost ip6-loopback
fe00::0 ip6-localnet
ff00::0 ip6-mcastprefix
ff02::1 ip6-allnodes
ff02::2 ip6-allrouters
ff02::3 ip6-allhosts
The error when I uncomment #SSLEngine on
XAMPP: Starting diagnose...
XAMPP: Your /etc/hosts is not okay. I will fix it.
XAMPP: Next try...

The reason is I have provided the privkey.pem in SSLCertificateFile & cert.pem in SSLCertificateKeyFile
#SSLCertificateFile /etc/letsencrypt/live/example.com/privkey.pem
#SSLCertificateKeyFile /etc/letsencrypt/live/example.com/cert.pem
After changing to this it worked fine & no need of SSLCertificateChainFile
SSLCertificateFile /etc/letsencrypt/live/example.com/fullchain.pem
SSLCertificateKeyFile /etc/letsencrypt/live/example.com/privkey.pem

Related

Cannot set up multiple virtual hosts via MAMP

I'm trying to set up virtual hosts for the projects in my MAMP htdocs folder. But I cannot create more than one, it seems. If, for example, I have this in my httpd-vhosts.conf file:
<VirtualHost *:80>
DocumentRoot "/Applications/MAMP/htdocs/first-project/public"
ServerName first-project.dev
</VirtualHost>
<VirtualHost *:80>
DocumentRoot "/Applications/MAMP/htdocs/second-project/public"
ServerName second-project.dev
</VirtualHost>
And I then point the browser to second-project.dev, it will show me the contents of first-project.dev. If I remove the v-host entry for first-project, then I can view second-project.dev with no problem. It doesn't like me having more than one entry, for some reason.
I have the following in my /etc/hosts file:
##
# Host Database
#
# localhost is used to configure the loopback interface
# when the system is booting. Do not change this entry.
##
127.0.0.1 localhost
127.0.0.1 first-project.dev
127.0.0.1 second-project.dev
255.255.255.255 broadcasthost
::1 localhost
Am I missing something? Maybe a setting in httpd.conf?
I found the answer to my own question. When establishing multiple virtual host entries, you need the following line before the entries:
NameVirtualHost *:80
Also, you need to establish the desired directory to replace the default localhost:
<VirtualHost *:80>
DocumentRoot "/Applications/MAMP/htdocs/"
ServerName localhost
</VirtualHost>
My full httpd-vhosts.conf file:
NameVirtualHost *:80
<VirtualHost *:80>
DocumentRoot "/Applications/MAMP/htdocs/"
ServerName localhost
</VirtualHost>
<VirtualHost *:80>
DocumentRoot "/Applications/MAMP/htdocs/sampleapp/public/"
ServerName sampleapp.dev
</VirtualHost>
<VirtualHost *:80>
DocumentRoot "/Applications/MAMP/htdocs/simplewebsite/public/"
ServerName simplewebsite.dev
</VirtualHost>

Ubuntu 14.04 Redirect Domain to Port

I am trying to direct mydomain.com to a specific port. I have run netstat and I know that my code is listening at 0.0.0.0:3000. I have the following in /etc/apache2/sites-available
<VirtualHost *:80>
ProxyPreserveHost On
ProxyRequests Off
ServerName mydomain.com
ServerAlias www.mydomain.com
ProxyPass / http://0.0.0.0:3000/
ProxyPassReverse / http://0.0.0.0:3000/
</VirtualHost>
I was able to get other domains redirected to a subdirectory. When I test using mydomain.com from a browser, I see the default page.

How to redirect different URLs to different ports on the same domain?

I have odoo running on port 8069 and I want to run wordpress on port 80 on the same domain. I would like to redirect example.com* to port 8069 except example.com/wordpress* which I want to go to port 80.
I know this is similar to Redirecting from port 80 to different ports based on URL. I want to implement a reverse proxy solution as advised by abhi-devireddy. I tried the following reverse proxy. All requests are forwarded to port 8069 including http://example.com/wordpress/. Odoo reports error 404 page not found when browser points to http://example.com/wordpress
<VirtualHost *:80>
ServerName odoo
ErrorLog /var/log/odoo/odoo-error.log
CustomLog /var/log/odoo/odoo-access.log combined
<Proxy *>
Order deny,allow
Allow from all
</Proxy>
ProxyRequests Off
ProxyPreserveHost On
ProxyPass / http://example.com:8069/
ProxyPassReverse / http://example.com:8069/
ProxyPass http://example.com/wordpress/ http://example.com:80/wordpress
ProxyPassReverse http://example.com/wordpress/ http://example.com:80/wordpress
ProxyVia On
LogLevel warn
</VirtualHost>
ProxyPass ! excludes the URL http://example.com:80/wordpress from the reverse proxy. This allows everything except http://example.com:80/wordpress to be mapped to port 8069 while leaving http://example.com:80/wordpress to go through to port 80:
<VirtualHost *:80>
ServerName odoo
ErrorLog /var/log/odoo/odoo-error.log
CustomLog /var/log/odoo/odoo-access.log combined
<Proxy *>
Order deny,allow
Allow from all
</Proxy>
ProxyRequests Off
ProxyPass /wordpress !
ProxyPass / http://example.com:8069/
ProxyPassReverse / http://example.com:8069/
Alias /wordpress /var/lib/wordpress/
# ProxyVia On
LogLevel warn
</VirtualHost>

Virtual Host is not working in Zend Framework after multiple tries at fixing things

In both the sites-available and sites-enabled folders, I have a conf file called "zend-framework.conf". This is what I have contained in the file.
<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 zendlocalhost
ServerAlias zendlocalhost
ServerAdmin root#localhost
DocumentRoot /var/www/zend-framework/public
SetEnv APPLICATION_ENV "development"
<Directory /var/www/zend-framework/public>
DirectoryIndex index.php
AllowOverride All
Order allow,deny
Allow from All
</Directory>
# 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
This is what I have in my etc/hosts file
127.0.0.1 localhost
#127.0.1.1 lazerorca-iMac
127.0.0.1 zendlocalhost
# The following lines are desirable for IPv6 capable hosts
::1 ip6-localhost ip6-loopback
fe00::0 ip6-localnet
ff00::0 ip6-mcastprefix
ff02::1 ip6-allnodes
ff02::2 ip6-allrouters
This is what I have in my ports.conf file. I get a message saying that NameVirtualHost *:80 is going to be deprecated in a later version. I tried adding that only because I saw it in another question
# 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
<IfModule ssl_module>
Listen 443
</IfModule>
<IfModule mod_gnutls.c>
Listen 443
</IfModule>
NameVirtualHost *:80
# vim: syntax=apache ts=4 sw=4 sts=4 sr noet
This is the error I get when I go to http://zendlocalhost
Internal Server Error
The server encountered an internal error or misconfiguration and was
unable to complete your request.
Please contact the server administrator at root#localhost to inform
them of the time this error occurred, and the actions you performed
just before this error.
More information about this error may be available in the server error
log.
This is what access.log says
127.0.0.1 - - [16/Dec/2014:15:05:22 -0500] "GET / HTTP/1.1" 500 798 "-" "Mozilla/5.0 (X11; Ubuntu; Linux i686; rv:35.0) Gecko/20100101
Firefox/35.0"
This is what the error.log says
[Tue Dec 16 15:25:20.271792 2014] [core:alert] [pid 4825] [client
127.0.0.1:60826] /var/www/zend-framework/public/.htaccess: Invalid command 'RewriteEngine', perhaps misspelled or defined by a module not
included in the server configuration
I check the .htaccess file and it looks ok to me, but evidently it isn't. here is what is in the .htaccess file
RewriteEngine On
# The following rule tells Apache that if the requested filename
# exists, simply serve it.
RewriteCond %{REQUEST_FILENAME} -s [OR]
RewriteCond %{REQUEST_FILENAME} -l [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^.*$ - [NC,L]
# The following rewrites all other queries to index.php. The
# condition ensures that if you are using Apache aliases to do
# mass virtual hosting, the base path will be prepended to
# allow proper resolution of the index.php file; it will work
# in non-aliased environments as well, providing a safe, one-size
# fits all solution.
RewriteCond %{REQUEST_URI}::$1 ^(/.+)(.+)::\2$
RewriteRule ^(.*) - [E=BASE:%1]
RewriteRule ^(.*)$ %{ENV:BASE}index.php [NC,L]
Interestingly enough if I go to http://zendlocalhost/phpmyadmin it pulls up
If I go to 127.0.0.1, it pulls up the generic Ubuntu apache index.html file
I am very new to Zend as in this is my first time trying it out. i know there are some crazy URL rewriting and such. I would have thought going to the root address would have pulled up the index.php file.
Thanks in advance for your help
Apache doesn't understand RewriteEngine, the very first directive in your .htaccess. This means mod_rewrite is not enabled. If you're on Ubuntu, run sudo a2enmod rewrite, and then restart Apache and try again.

How to rewrite a domain to a subfolder

I have one local server called server1 with a subdirectory sub (server1/sub/).
Now i have a dns entry which redirects server2 to server1.
I want to configure my apacher server in a way that when I open server2 in a browser I get the content from server1/sub/.
The url should not change to server1/sub/.
Is this possible with mod_rewrite?
EDIT:
I added
127.0.0.1 localhost
127.0.0.1 wiki2
127.0.0.1 wiki3
to the hosts file and
VirtualHost 127.0.0.1>
ServerName wiki2
ServerAlias 127.0.0.1
DocumentRoot c:/xampp/htdocs/wiki_angua
<Directory c:/xampp/htdocs/wiki_angua >
Allow From All
</Directory>
</VirtualHost>
<VirtualHost 127.0.0.1>
ServerName wiki3
ServerAlias 127.0.0.1
DocumentRoot c:/xampp/htdocs/weatherwax
<Directory c:/xampp/htdocs/weatherwax >
Allow From All
</Directory>
</VirtualHost>
to httpd.conf and restarted apache.
Whether I open wiki2 or wiki3 I land in ./wiki_angua.
Is there anything I forgot?
If you have a DNS entry for server2 then the Host HTTP request header will be correctly set, and all you need then is a virtual host, without the need to use mod_rewrite.
For example:
<VirtualHost *:80>
ServerName server2
DocumentRoot /path/to/server1/sub
<Directory /path/to/server1/sub>
Allow From All
</Directory>
# ... etc
</VirtualHost>
edit:
In the case you still want to use mod_rewrite you can do something like:
RewriteCond %{HTTP_HOST} ^server2$
RewriteRule ^(.+) /path/to/server1/sub/$1
This must be located in the global server configuration, and not in an existing virtual host.