I'm trying to get my node app running by just typing in the regular domain instead of appending a dev port at the end (:8081). I cant seem to get it working right, it appears like the reverse proxy virtual host I set up in the conf file is just being ignored. My httpd.conf file gets automatically generated so I have this in a pre_virtualhost_global.conf file:
<VirtualHost *:443>
ServerName www.statementdigest.com
SSLEngine On
ProxyPreserveHost On
ProxyRequests Off
<Directory "/home/statementdigest/myapp">
AllowOverride All
</Directory>
# Set the path to SSL certificate
# Usage: SSLCertificateFile /path/to/cert.pem
SSLCertificateFile /var/cpanel/ssl/cpanel/mycpanel.pem
SSLCertificateKeyFile /var/cpanel/ssl/cpanel/mycpanel.pem
SSLCertificateChainFile /var/cpanel/ssl/cpanel/mycpanel.pem
# Servers to proxy the connection, or;
# List of application servers:
# Usage:
# ProxyPass / http://[IP Addr.]:[port]/
# ProxyPassReverse / http://[IP Addr.]:[port]/
# Example:
<Location /appserver.js>
ProxyPass http://127.0.0.1:8081
ProxyPassReverse http://127.0.0.1:8081
</Location>
# Or, balance the load:
# ProxyPass / balancer://balancer_cluster_name
</VirtualHost>
apachectl -S shows
173.237.185.229:80 is a NameVirtualHost
default server 173.237.185.229 (/etc/apache2/conf/httpd.conf:259)
port 80 namevhost 173.237.185.229 (/etc/apache2/conf/httpd.conf:259)
alias server.statementdigest.com
port 80 namevhost statementdigest.com (/etc/apache2/conf/httpd.conf:325)
alias mail.statementdigest.com
alias www.statementdigest.com
port 80 namevhost proxy-subdomains-vhost.localhost (/etc/apache2/conf/httpd.conf:523)
wild alias cpanel.*
wild alias whm.*
wild alias webmail.*
wild alias webdisk.*
wild alias cpcalendars.*
wild alias cpcontacts.*
173.237.185.229:443 is a NameVirtualHost
default server statementdigest.com (/etc/apache2/conf/httpd.conf:394)
port 443 namevhost statementdigest.com (/etc/apache2/conf/httpd.conf:394)
alias mail.statementdigest.com
alias www.statementdigest.com
alias cpanel.statementdigest.com
alias webdisk.statementdigest.com
alias whm.statementdigest.com
alias webmail.statementdigest.com
port 443 namevhost proxy-subdomains-ssl-default-vhost.localhost (/etc/apache2/conf/httpd.conf:624)
wild alias cpanel.*
wild alias whm.*
wild alias webmail.*
wild alias webdisk.*
wild alias cpcalendars.*
wild alias cpcontacts.*
port 443 namevhost server.statementdigest.com (/etc/apache2/conf/httpd.conf:755)
127.0.0.1:80 proxy-subdomains-vhost.localhost (/etc/apache2/conf/httpd.conf:523)
127.0.0.1:443 proxy-subdomains-ssl-default-vhost.localhost (/etc/apache2/conf/httpd.conf:624)
*:* server.statementdigest.com (/etc/apache2/conf/httpd.conf:285)
*:443 is a NameVirtualHost
default server www.statementdigest.com (/etc/apache2/conf.d/includes/pre_virtualhost_global.conf:4)
port 443 namevhost www.statementdigest.com (/etc/apache2/conf.d/includes/pre_virtualhost_global.conf:4)
port 443 namevhost server.statementdigest.com (/etc/apache2/conf/httpd.conf:755)
ServerRoot: "/etc/apache2"
Main DocumentRoot: "/etc/apache2/htdocs"
Main ErrorLog: "/etc/apache2/logs/error_log"
Mutex ssl-stapling: using_defaults
Mutex proxy: using_defaults
Mutex ssl-cache: dir="/run/apache2" mechanism=fcntl
Mutex default: dir="/var/run/apache2/" mechanism=default
Mutex mpm-accept: using_defaults
Mutex rewrite-map: dir="/run/apache2" mechanism=fcntl
Mutex ssl-stapling-refresh: using_defaults
PidFile: "/run/apache2/httpd.pid"
Define: DUMP_VHOSTS
Define: DUMP_RUN_CFG
Define: MODSEC_2.5
Define: MODSEC_2.9
User: name="nobody" id=99
Group: name="nobody" id=99
typing in the domain still routes to the cgi-bin page so it seems like the virtual host proxy is just being ignored. I will gladly provide any more details that are needed, please ask. I've been grinding on this a few days now and i'm a bit stuck, any help or direction would be very much appreciated, thank you!
Related
I have an EC2 server running Amazon Linux AMI.
I have a number of websites running on the server and have an httpd-vhosts.conf file setup.
<VirtualHost *:80>
ServerAdmin webmaster#localhost
DocumentRoot "/vol2/html-studio/www"
ServerName "studioofcrayons.com"
ErrorLog "logs/studioofcrayons.com-error_log"
CustomLog "logs/studioofcrayons.com-access_log" common
</VirtualHost>
<VirtualHost *:80>
ServerAdmin webmaster#localhost
DocumentRoot "/vol2/html-studio/www"
ServerName "www.studioofcrayons.com"
ErrorLog "logs/studioofcrayons.com-error_log"
CustomLog "logs/studioofcrayons.com-access_log" common
</VirtualHost>
This site works correctly, as do the others I have setup.
Recently though I have added
<VirtualHost *:80>
ServerAdmin webmaster#localhost
DocumentRoot "/vol2/html-snr/www"
ServerName "sundaynightraving.com"
ErrorLog "logs/sundaynightraving.com-error_log"
CustomLog "logs/sundaynightraving.com-access_log" common
</VirtualHost>
<VirtualHost *:80>
ServerAdmin webmaster#localhost
DocumentRoot "/vol2/html-snr/www"
ServerName "www.sundaynightraving.com"
ErrorLog "logs/sundaynightraving.com-error_log"
CustomLog "logs/sundaynightraving.com-access_log" common
</VirtualHost>
www.sundaynightraving.com works, but for some reason going to sundaynightraving.com redirects to the studioofcrayons.com website and URL instead.
I cannot see anything in the logfiles, there doesn't appear to be any errors being generated.
httpd -t returns 'syntax ok'
httpd -S returns
VirtualHost configuration:
*:80 is a NameVirtualHost
default server studioofcrayons.com (/etc/httpd/conf/httpd-vhosts.conf:1)
port 80 namevhost studioofcrayons.com (/etc/httpd/conf/httpd-vhosts.conf:1)
port 80 namevhost www.studioofcrayons.com (/etc/httpd/conf/httpd-vhosts.conf:9)
port 80 namevhost sofc.uk (/etc/httpd/conf/httpd-vhosts.conf:17)
port 80 namevhost www.sofc.uk (/etc/httpd/conf/httpd-vhosts.conf:25)
port 80 namevhost oneillmtc.co.uk (/etc/httpd/conf/httpd-vhosts.conf:33)
port 80 namevhost www.oneillmtc.co.uk (/etc/httpd/conf/httpd-vhosts.conf:41)
port 80 namevhost datasaab.com (/etc/httpd/conf/httpd-vhosts.conf:49)
port 80 namevhost www.datasaab.com (/etc/httpd/conf/httpd-vhosts.conf:57)
port 80 namevhost sundaynightraving.com (/etc/httpd/conf/httpd-vhosts.conf:65)
port 80 namevhost www.sundaynightraving.com (/etc/httpd/conf/httpd-vhosts.conf:73)
ServerRoot: "/etc/httpd"
Main DocumentRoot: "/vol2"
Main ErrorLog: "/etc/httpd/logs/error_log"
Mutex default: dir="/var/run/httpd/" mechanism=default
Mutex mpm-accept: using_defaults
Mutex cache-socache: using_defaults
Mutex authdigest-opaque: using_defaults
Mutex watchdog-callback: using_defaults
Mutex proxy-balancer-shm: using_defaults
Mutex rewrite-map: using_defaults
Mutex authdigest-client: using_defaults
Mutex lua-ivm-shm: using_defaults
Mutex proxy: using_defaults
Mutex authn-socache: using_defaults
PidFile: "/var/run/httpd/httpd.pid"
Define: DUMP_VHOSTS
Define: DUMP_RUN_CFG
User: name="apache" id=48
Group: name="apache" id=48
Is there something I have missed, or something else I can check?
Does anyone have any ideas?
The issue I had now appears to have resolved itself overnight.
I have a amazon ec2 instance using Ubuntu server 18.04, I configured the config files and added them to sites-enable by doing sudo a2ensite. Port 88 is not accesible only port 80. Can someone tell me what the problem of this? Should I inclue the IP? Do i need to apply elastic IP on it in order to work? since i am using the public IP on this one.
PS: my account on amazon is free tier subscription meaning, i can only make one instance. I am using ubuntu 18.04. Im deploying laravel application
ports.conf
Listen 80
Listen 88
<IfModule ssl_module>
Listen 443
</IfModule>
<IfModule mod_gnutls.c>
Listen 443
</IfModule>
Port 80 (main project) 000-default.conf
<VirtualHost *:80>
ServerAdmin webmaster#localhost
DocumentRoot /var/www/html/capstoneproject/public
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
<Directory "/var/www/html/capstoneproject/public">
AllowOverride all
Require all granted
Options Indexes FollowSymLinks
Order allow,deny
Allow from all
</Directory>
</VirtualHost>
# vim: syntax=apache ts=4 sw=4 sts=4 sr noet
Port 88
<VirtualHost *:88>
ServerAdmin webmaster#localhost
DocumentRoot /var/www/html/Inventory/public
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
<Directory "/var/www/html/Inventory/public">
AllowOverride all
Require all granted
Options Indexes FollowSymLinks
Order allow,deny
Allow from all
</Directory>
</VirtualHost>
Already tried restarting apache but wont work.
UPDATE:
i tried running netstat -anp | grep apache2 and i got
tcp6 0 0 :::88 :::* LISTEN 11685/apache2
tcp6 0 0 :::80 :::* LISTEN 11685/apache2
Still wont work. why?
You'll need to modify the Security Group in EC2.
From the EC2 dashboard, go to the "Instances" tab and click on your instance. Then go to the Security Group section and click on "view inbound rules". You'll be able to see the ports open. You'll need to change the Security Group rules your instance is connected to. Click on the security group name in the panel where you saw "view inbound rules". It should take you to another page where you will be able to edit all the firewall rules.
I have a fresh VPS on Ubuntu 18. Have installed only PHP and Apache. Created only a one vhost config:
<VirtualHost *:80>
ServerName vp123.ovh.net
DocumentRoot /var/www/app
</VirtualHost>
After apache realod, the domain is pointing to default folder /var/www/html instead of my /var/www/app
000-default.conf is default:
<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 www.example.com
ServerAdmin webmaster#localhost
DocumentRoot /var/www/html
# 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>
apache2ctl -S outputs:
VirtualHost configuration:
*:80 is a NameVirtualHost
default server vp123.ovh.net (/etc/apache2/sites-enabled/000-default.conf:1)
port 80 namevhost vp123.ovh.net (/etc/apache2/sites-enabled/000-default.conf:1)
port 80 namevhost vp123.ovh.net (/etc/apache2/sites-enabled/vp123.ovh.net.conf:1)
ServerRoot: "/etc/apache2"
Main DocumentRoot: "/var/www/html"
Main ErrorLog: "/var/log/apache2/error.log"
Mutex default: dir="/var/run/apache2/" mechanism=default
Mutex mpm-accept: using_defaults
Mutex watchdog-callback: using_defaults
PidFile: "/var/run/apache2/apache2.pid"
Define: DUMP_VHOSTS
Define: DUMP_RUN_CFG
User: name="www-data" id=33
Group: name="www-data" id=33
When pointing a new domain to this server - works perfect. But this "default domain" is always pointing to default folder. Disabling 000-default.conf helps but I don't want do that.
The virtual host defined at 000-default.conf doesn't have a ServerName directive so it inherits the value from its parent container (in this case the main server settings) and I presume such directive also has vp123.ovh.net as value. Thus Apache considers the first virtual host matches.
A ServerName should be specified inside each <VirtualHost> block. If it is absent, the ServerName from the "main" server configuration will be inherited.
Since you want to use that name elsewhere a possible solution is to set a explicit value that doesn't interfere, e.g.:
<VirtualHost *:80>
ServerName localhost
DocumentRoot /var/www/html
</VirtualHost>
Apache selects the virtual host as described in the documentation.
Considering the vhost selection process your options are:
Disable the default vHost, you don't need it.
Really. Why would you want to keep it?
Change the default vHost declaration to <VirtualHost *>. Therefore making the other vHost the default for requests targeted at port 80.
Add your servers ip address to your vhost declaration. (<VirtualHost 1.2.3.4:80>) It will then take precedence over the default vhost *:80 for requests targeted at that IP-address. Note that requests to other to other IPs of your server will still be served by the *:80-vHost.
Set DocumentRoot /var/www/app inside your default vHost. This will require you to make configuration changes in multiple vHost each time and thus increases the chance of making mistakes.
I'm trying to set up a reverse proxy with an Apache2 server accepting requests at port 443 (to enable https). The idea is to have the Apache2 server accept the request and forward it on to my Node server, which is listening on port 4443. I've looked through several example configurations for setting up the virtual hosts, and after toggling a few options I still get the 502 error. Both servers are hosted on a DigitalOcean droplet running Ubuntu 14.04.
I can hit port 4443 directly in Chrome and it serves the Node app. When I load the site without a port number, it loads port 443 (as expected) and I get this error:
Proxy Error
The proxy server received an invalid response from an upstream server.
The proxy server could not handle the request GET /.
Reason: Error reading from remote server
Apache/2.4.7 (Ubuntu) Server at [domain.com] Port 443
In the console, it says:
Failed to load resource: the server responded with a status of 502 (Proxy Error)
Here are the resources I'm following:
https://www.digitalocean.com/community/tutorials/how-to-use-apache-http-server-as-reverse-proxy-using-mod_proxy-extension
https://support.mayfirst.org/wiki/how-to/servers/configure-nodejs-with-apache
This is my config file. The actual IP and domain are replaced with [IP] and [domain.com].
<IfModule mod_ssl.c>
<VirtualHost *:443>
# 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 www.example.com
ServerAdmin admin#[domain.com]
ServerName [domain.com]
ServerAlias www.[domain.com]
DocumentRoot /var/www/[domain.com]/public_html
#SSL Configuration
SSLEngine On
SSLProxyEngine On
SSLCertificateFile /etc/letsencrypt/live/[domain.com]/cert.pem
SSLCertificateKeyFile /etc/letsencrypt/live/[domain.com]/privkey.pem
Include /etc/letsencrypt/options-ssl-apache.conf
SSLCertificateChainFile /etc/letsencrypt/live/[domain.com]/chain.pem
ProxyPreserveHost On
ProxyRequests off
ProxyPass / http://[IP]:4443/ retry=1 acquire=3000 timeout=3000 Keepalive=On
ProxyPassReverse / http://[IP]:4443/
# 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
</IfModule>
How can I edit my config file to resolve this 502 error?
My question is probably trivial and a duplicate, but either I cannot formulate it or it's not been answered on SO yet.
I have two webservers on a Digital Ocean droplet. One is listening on port 80 and can be accessed via example.com (DNS are on route 53), and the other is on port 8080: how can I make it accessible from example-2.com?
I suppose the software I'm looking for would intercept the HTTP requests, check the referrer, and route those coming from example.com to port 80 and those coming from example-2.com to port 8080. What is it?
This can not be done using only DNS. By default web browsers attempt to connect to port 80 when the url starts with "http" without specifying a port. The user would have to know to connect to port 8080 and explicitly access the URL as
http://example-2.com:8080
I am assuming you are running both web server instances on the same OS environment/IP address, though this would also work for separate hosting environments. What you probably want is a reverse web proxy which can inspect the requested domain name and route to an appropriate server instance. You would run the reverse web proxy on port 80, and probably move the server you are currently running on port 80 to another port (say, 8081).
Apache with mod_proxy and the virtual hosting settings is a possible solution. Assuming example.com and example-2.com point to the Apache instance configure it something like this:
<VirtualHost *:80>
ServerName example.com
ServerAdmin webmaster#example.com
ProxyRequests off
ProxyPreserveHost on
ProxyPass / http://localhost:8081/
ProxyPassReverse / http://localhost:8081/
<Proxy *>
Order allow,deny
Allow from all
</Proxy>
</VirtualHost>
<VirtualHost *:80>
ServerName example-2.com
ServerAdmin webmaster#example-2.com
ProxyRequests off
ProxyPreserveHost on
ProxyPass / http://localhost:8080/
ProxyPassReverse / http://localhost:8080/
<Proxy *>
Order allow,deny
Allow from all
</Proxy>
</VirtualHost>