how to access virtual host outside - linux

I have this on my Apache 2 file "example.com.conf". I am only able to access it only by IP, but when I try to access it for the server name always I got the following error:
Network Error (dns_server_failure)
<VirtualHost *:80>
ServerAdmin myemail
DocumentRoot /var/www/html/example.com
ServerName example.com
ServerAlias www.example.com
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
I'm running Ubuntu 14.04.03 (X64)
I try to access this on a machine with Windows 8.1.

Related

port redirection of my nodejs application with apache2

My system is hosted by Amazon LighSail.
My application is running with Nodejs on the port 3000.
I installed my HTTPS certificate for my domain name with Let's Encrypt.
Now I want to reach my nodejs application directly to my sub-domain.domain.com.
When I go to my domain name (sub-domain.domain.com), I'm directed to the bitnami home page.
So I have:
https://sub-domain.domain.com --> bitnami home page
IP-ADDRESS:3000 --> my nodejs application
I add a proxy to redirect all HTTP request to my port 3000 but with no sucess.
My proxy added in /etc/apache2/sites-enabled/000-default.conf :
< VirtualHost *:80 >
ServerAdmin webmaster#localhost
ServerName www.sub-domain.domain.com
ProxyPass / http://127.0.0.1:3000/
ProxyPassReverse / http://127.0.0.1:3000/
DocumentRoot /var/www/html
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
< / VirtualHost >
Someone has an idea to solve my problem or any clue?
With SSL Cert the config should look more like this:
<VirtualHost *:80>
ServerName yoursite.com
ServerAlias *yoursite.com
ServerAdmin example#yoursite.com
DocumentRoot /var/www/yourSite
LogLevel debug
SSLEngine on
SSLCertificateFile /path/to/lets/encrypt/cert
SSLCertificateKeyFile /path/to/lets/encrypt/key
SSLProxyEngine on
ProxyPass "/" "http://127.0.0.1:3000/"
ProxyPassReverse "/" "http://127.0.0.1:3000/"
ErrorLog ${APACHE_LOG_DIR}/yourSite_error_https.log
CustomLog ${APACHE_LOG_DIR}/yourSite_access_https.log combined
</VirtualHost>
Solved ! I had to add my proxy in this file: /opt/bitnami/apache2/conf/bitnami/bitnami.conf

Apache ReverseProxy not working with Node and SSL

I'm trying to setup my app on HTTPS on a web server. I have a valid certificate that is installed on my InMotion host using AutoSSL. I have the node app running on my Centos server on port 3000 and my apache SSL server running on port 443. To route requests made to my website, I am attempting to create a reverse-proxy. I made a file called default-site.conf which is stored in /etc/http.d/conf.d and has the following contents:
<VirtualHost _default_:443>
SSLProxyEngine on
ServerName example.com
ServerAlias www.example.com
ProxyRequests Off
ProxyPreserveHost On
ProxyVia Full
<Proxy *>
Require all granted
</Proxy>
ServerAdmin info#example.com
DocumentRoot /home/USER/my-app/public
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
SSLCertificateFile /home/USER/ssl/certs/certificate.crt
SSLCertificateKeyFile /home/USER/ssl/keys/certificate.key
ProxyPass / https://example.com:3000/
ProxyPassReverse / https://example.com:3000 /
<Directory "/home/USER/my-app/public">
AllowOverride All
</Directory>
</VirtualHost>
I will emphasize that the app is accessible at http://example.com:3000 (insecure) but when I attempt to go to https://example.com (secure) I get my blank index.html with a 404 error:
[Error] Failed to load resource: the server responded with a status of 404 (Not Found) (index.js, line 0)
I managed to fix this issue by completely simplifying my config to the following two lines:
ProxyPass / http://127.0.0.1:3000/
ProxyPassReverse / http://127.0.0.1:3000/
This may not be the most flexible approach but it reroutes the traffic the way I need it to be routed, so for my purposes, it works.

How to access website from apache2 (linux from GCP) from other port than 80?

I want to host a WordPress website on Google Cloud with Linux Instance.
There is already running website on port 80 and I want my new site to be hosted on any port other than 80.
I have changed following ports.conf and mywebsite.conf to achieve this
/etc/apache2/ports.conf
Existing Code
Listen 80
New Code
Listen 80
Listen 8080
I have created following file with VirtualHost
/etc/apache2/sites-available/mywebsite.conf
with Code
<VirtualHost *:8080>
ServerAdmin adminemail#gmail.com
DocumentRoot /var/www/mywebsite.com
<Directory />
Options FollowSymLinks
AllowOverride None
</Directory>
<Directory /var/www/mywebsite.com/>
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Order allow,deny
allow from all
</Directory>
ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/
<Directory "/usr/lib/cgi-bin">
AllowOverride None
Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch
Order allow,deny
Allow from all
</Directory>
ErrorLog ${APACHE_LOG_DIR}/error.log
# Possible values include: debug, info, notice, warn, error, crit,
# alert, emerg.
LogLevel warn
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
After making these changes i just ran some commands as follows
$sudo a2ensite mywebsite.conf
$service apache2 restart
But when I hit my websites url as http://IPAdressOfServer:8080/ server is returning ERR_CONNECTION_TIMED_OUT.
What exactly I will have to do to make this correct?
You have to open the firewall port 8080 from your Google Project console. See this link: https://console.cloud.google.com/networking/firewalls/list?project=[your-project-id]. Replace your-project-id with the id of your Google Project

Is it possible to use node.js server without having the Port number appear in the URL.

I have a VPS using apache on port 80, but want to use node.js for a subdomain, without the port node will be using appear in the address bar.
Yes it is possible
In your apache virtual host file configure with the following:
<VirtualHost *:80>
ServerName subdomain.myapp.com
ProxyRequests off
<Proxy *>
Order allow,deny
Allow from all
</Proxy>
ProxyPass / http://localhost:3000/
ProxyPassReverse / http://localhost:3000/
ProxyPreserveHost on
</VirtualHost>
You should have
NameVirtualHost *:80

Run a NodeJS app with Apache

I have a ubuntu server running a few apache websites. I want to run a nodejs app on the same server. I have the app running on the server now out of port 3000 (www.example.com:3000) no problems there.
I now want to direct a new domain to the nodejs app with my existing apache setup. Below is an example of the config i'm running however it's pointing to a folder. What i require is the config that points to the app's port. And any extras that I maybe missing.
<VirtualHost *:80>
ServerAdmin spam#example.com
ServerName example.com
ServerAlias www.example.com
DocumentRoot /srv/www/example.com/public_html/
ErrorLog /srv/www/example.com/logs/error.log
CustomLog /srv/www/example.com/logs/access.log combined
</VirtualHost>
First of all, you should to install mod_proxy and mod_proxy_http.
Then you can use something like the following configuration:
<VirtualHost *:80>
ServerAdmin spam#example.com
ServerName example.com
ServerAlias www.example.com
ProxyRequests off
<Proxy *>
Order deny,allow
Allow from all
</Proxy>
<Location />
ProxyPass http://localhost:3000/
ProxyPassReverse http://localhost:3000/
</Location>
</VirtualHost>

Resources