How to redirect a pased on port and path in apache2? - apache2

I want to redirect a certain path on my server to another port:
<VirtualHost *:80>
ProxyPreserveHost On
ProxyPass /hello http://localhost:8090/
ProxyPassReverse /hello http://localhost:8090/
</VirtualHost>
/etc/apache2/sites-enabled$ ll
lrwxrwxrwx 1 root root 35 Aug 22 2017 000-default.conf -> ../sites-available/000-default.conf
When I access server:80/hello, I'm presented with a 404.
I also have:
sudo a2enmod proxy
sudo a2enmod proxy_http
What might be missing here?

While I don't know why, I could resolve it replacing localhost with 127.0.0.1.

Related

React what to use in production instead of proxy?

I know that the proxy setting in package.json only works in dev. So the question is:
How to make the application work in prod (after doing yarn build) and deploying into apache?
I've tried many things, nothing seems to work.
My REST API (server side) is a java running on :8080
When I deploy the app and try a request, the requests go to localhost/api instead of localhost:8080/api
My fetch all look like:
await fetch(`/api/group/${id}`, {.
What is the simplest and most flexible solution?
The only solution I found so far and it works is to configure VirtualHost on the apache server:
<VirtualHost *:80>
ServerAdmin webmaster#localhost
DocumentRoot /var/www/html
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
ProxyPreserveHost On
ProxyRequests Off
ServerName www.example.com
ServerAlias example.com
ProxyPass /api/ http://localhost:8080/api/
ProxyPassReverse /api/ http://localhost:8080/api/
</VirtualHost>
Then I had to enable modules and restart apache.
Steps (ubuntu):
cd /etc/apache2/sites-available
sudo cp 000-default.conf react.conf
sudo a2dissite 000-default.conf
sudo a2ensite react.conf
sudo a2enmod - here enabled * all
sudo systemctl restart apache2
Now my /api points to localhost:8080/api

Google Compute Engine Apache2 subdomain still directed a home instead of virtual host folder

I've been trying to create subdomains in my Google Cloud Console and then direct them to a folder in my /var/www directory.
I created a subdomain:
DNS Name: subdomain.example.com
Type: CNAME
TTL: 300
Data: example.com
I created a folder
/var/www/subdomain
I created a file with message "Subdomain!"
/var/www/subdomain/index.html
After, I duplicated my 000-default.conf
cp /etc/apache2/sites-available/000-default.conf /etc/apache2/sites-available/subdomain.conf
I edited the new file code to:
<VirtualHost *:80>
ServerAdmin webmaster#subdomain.example.com
DocumentRoot /var/www/subdomain
ServerName subdomain.example.com
ServerAlias www.subdomain.example.com
Redirect permanent / https://subdomain.example.com/
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
I then did
sudo a2ensite subdomain.conf
sudo service apache2 restart
Yet my subdomain is still directed at the document root /var/www/html
I noticed that when I do systemctl reload apache2 I get error Failed to connect to bus: No such file or directory
Did I miss a step or do I need to add something else?
The problem is that http is configured but not https.
Must add to default-ssl.conf
<VirtualHost *:443>
ServerName www.yoursite.com
DocumentRoot /var/www/site
SSLEngine on
SSLCertificateFile /path/to/www_yoursite_com.crt
SSLCertificateKeyFile /path/to/www_yoursite_com.key
SSLCertificateChainFile /path/to/DigiCertCA.crt
</VirtualHost>

Dancer2 - Cannot deploy with Apache2 using Plack

I am trying to deploy Dancer2 app using Plack on Apache2. But after changing all the configurations on port 80 - it shows me directory listing instead of the application itself
Here is my running application on local:
root#dancer-cmuscheduler:/home/ADI/dancer_scheduler# plackup
bin/app.psgi HTTP::Server::PSGI: Accepting connections at
http://0:5000/
This runs just fine on port 5000.
However, I would like to deploy on apache2. Here is my configruations:
<VirtualHost *:80>
ServerAdmin webmaster#localhost
DocumentRoot /data
SetEnv DANCER_ENVIRONMENT "production"
<Directory /var/www/cmuscheduler>
AllowOverride None
Order allow,deny
Allow from all
</Directory>
<Location />
SetHandler perl-script
PerlResponseHandler Plack::Handler::Apache2
PerlSetVar psgi_app /var/www/cmuscheduler/bin/app.psgi
</Location>
ErrorLog ${APACHE_LOG_DIR}/error.log
</VirtualHost>
I have been trying to debug for 4 hours now. The funny thing is there is no helpful logs in the log file associated that would nudge me in the right direction
[Thu Jul 14 02:23:14.424149 2016] [mpm_event:notice] [pid 7468:tid
140401436669824] AH00489: Apache/2.4.7 (Ubuntu) configured -- resuming
normal operations [Thu Jul 14 02:23:14.424306 2016] [core:notice] [pid
7468:tid 140401436669824] AH00094: Command line: '/usr/sbin/apache2'
Please advice

Apache2 Virtual Host 503 error

Here is my apache2 virtual host config -
<VirtualHost *:80>
ServerName A.B.com
ProxyPreserveHost Off
ProxyPass / http://<ServerIP>:<appPort>/<app>/ timeout=3600 Keepalive=On
ProxyPassReverse / http://<ServerIP>:<appPort>/<app>/
ProxyTimeout 3600
</VirtualHost>
<Location "/">
Order allow,deny
Allow from all
</Location>
I have a route 53 entry for A.B.com pointing to this machine (the one with apache2)
I have ran a2ensite.. I am getting a 503 service unavailable on hitting A.B.com
However, A.B.com:appPort/app is working..
This definitely means I am missing something in apache2 configuration.. Can anyone point me out?
ProxyPreserveHost Off
should be on, and not need to mention http://, but in route you can mention http://.
further please check and paste error logs.

Warning while restarting the apache2 server

When restarting the apache2 server, I'm getting a warning.
$ sudo service apache2 restart
* Restarting web server apache2
[Tue Sep 02 10:38:54 2014] [warn] NameVirtualHost *:80 has no VirtualHosts
[Tue Sep 02 10:38:54 2014] [warn] NameVirtualHost *:80 has no VirtualHosts
How do I resolve this warning?
The problem here is that there's a misconfiguration in your server. You want to make sure the values of Listen, NameVirtualHost and VirtualHost all match. In your case, I'd expect:
Listen *:80
NameVirtualHost *:80
<VirtualHost *:80>
ServerName ...
DocumentRoot ...
...
</VirtualHost>

Resources