Reverse proxy for Jenkins in apache - linux

I installed jenkins on my local machine. It's avaliable localhost:8080. I want to configure that I be able to Jenkins from localhost/jenkins
I tryed to put this in my 000-default.conf:
<VirtualHost *:80>
ProxyPreserveHost On
ProxyPass / http://127.0.0.1:8080/
ProxyPassReverse / http://127.0.0.1:8080/
</VirtualHost>

Related

How to configure apache to forward https requests to a Strapi/node application running on port 1337?

I have a Strapi/node js application running on port 1337, and I can reach it with:
http://my-ip:1337
I also have a domain associated in the same server and a working ssl certificate in apache2, so that in the browser I can use https:
https://my-domain.com
Now, when I try to use https to reach port 1337 like this:
https://my-domain.com:1337
I get an "This site can’t provide a secure connection" error.
I tried to edit my my-domain.ssl.conf in apache 2 with the following code:
<IfModule mod_ssl.c>
<VirtualHost *:443>
ServerName www.my-domain
ServerAlias my-domain
DocumentRoot /var/www/my-domain/public_html
ErrorLog /var/www/my-domain/log/error.log
CustomLog /var/www/my-domain/log/requests.log combined
SSLProxyEngine On
ProxyPreserveHost On
ProxyPass / http://localhost:1337/
ProxyPassReverse / http://localhost:1337/
Include /etc/letsencrypt/options-ssl-apache.conf
SSLCertificateFile /etc/letsencrypt/live/my-domain/fullchain.pem
SSLCertificateKeyFile /etc/letsencrypt/live/my-domain/privkey.pem
</VirtualHost>
</IfModule>
But unluckily when I introduce the ProxyPass directive the server stops working without any meaningful error.
Both mod_proxy and mod_proxy_http are loaded in the apache2 configuration..
What could be the problem here? Thanks to anyone who can help with it!!
Strapi/node js application running on port 1337 to https
1st Changes
Edit /etc/apache2/sites-available/000-default.conf
ServerName yourdomian-name.com
ProxyPreserveHost On
SSLProxyEngine On
ProxyPass / http://localhost:1337/
ProxyPassReverse / http://localhost:1337/
ProxyPreserveHost On
SSLCertificateFile /etc/letsencrypt/live/yourdomian-name.com/fullchain.pem
SSLCertificateKeyFile /etc/letsencrypt/live/yourdomian-name.com/privkey.pem
2nd Changes
Edit this /etc/apache2/sites-available/000-default-le-ssl.conf
SSLCertificateFile /etc/letsencrypt/live/yourdomian-name.com/fullchain.pem
SSLCertificateKeyFile /etc/letsencrypt/live/yourdomian-name.com/privkey.pem
ServerName yourdomian-name.com
ProxyPreserveHost On
SSLProxyEngine On
ProxyPass / http://localhost:1337/
ProxyPassReverse / http://localhost:1337/
ProxyPreserveHost On
then restart apache2
sudo /etc/init.d/apache2 restart
Check https://yourdomian-name.com

.htaccess not working in Ubuntu 16.04 with Apache Web Server and Node.js app

I'm trying to set up a password-protected staging environment for a Nodejs/Express API server and web app server through the use of Apache HTTP Server and .htaccess.
However, the configuration below is not working, and I am able to access the Nodejs server via curl and the browser (port 80) without any restriction or password prompt.
My Nodejs app is located at /var/www/html/nodejs/app.js and is running via pm2 on port 8080.
I've placed my .htaccess file in /var/www/html/.htaccess, and it has the following content:
RewriteEngine on
AuthUserFile /home/user/safedirectory/.htpasswd
AuthGroupFile /dev/null
AuthName "Please Enter Password"
AuthType Basic
Require valid-user
My Apache config is located at /etc/apache2/sites-available/000-default.conf and has the following content:
<VirtualHost *:80>
ServerAdmin webmaster#localhost
DocumentRoot /var/www/html
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
ProxyRequests Off
ProxyPreserveHost On
ProxyVia Full
<Proxy *>
Require all granted
</Proxy>
<Location />
ProxyPass http://127.0.0.1:8080/
ProxyPassReverse http://127.0.0.1:8080/
</Location>
<Directory /var/www/html>
Options Indexes FollowSymLinks MultiViews
AllowOverride all
Order allow,deny
allow from all
</Directory>
</VirtualHost>
I've run the commands
sudo a2ensite 000-default.conf
and
sudo a2enmod rewrite
but to no avail.
FYI, I've used the following sites as resources:
How to use the .htaccess file
Set Up a Node.js App for a Website With Apache on Ubuntu 16.04
How To Rewrite URLs with mod_rewrite for Apache on Ubuntu 16.04
How To Use Apache as a Reverse Proxy with mod_proxy on Ubuntu 16.04
How To Install the Apache Web Server on Ubuntu 16.04
Any help would be much appreciated. Thanks.
Never use .htaccess if you have access to Apache configuration files. You can find the explanation here.
In your case, .htaccess is even not applied since requests never reach the folder, they are immediately proxied.
Try this:
<VirtualHost *:80>
ServerAdmin webmaster#localhost
DocumentRoot /var/www/html
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
ProxyRequests Off
ProxyPreserveHost On
ProxyVia Full
<Location />
AuthUserFile /home/user/safedirectory/.htpasswd
AuthGroupFile /dev/null
AuthName "Please Enter Password"
AuthType Basic
Require valid-user
ProxyPass http://127.0.0.1:8080/
ProxyPassReverse http://127.0.0.1:8080/
</Location>
</VirtualHost>

Apache and Node on same IP

I have a single VPS with one IP. I'm using Apache to serve cloud.mysite.com and I have a NodeJS application listening on port 3000.
I'm trying to configure my VPS in a way so that when I visit mysite.com, I get my NodeJS application.
Instead, when I visit mysite.com, I'm forwarded to cloud.mysite.com.
My .conf files are below.
mysite.com.conf
<VirtualHost mysite.com:80>
ServerName mysite.com
ProxyPreserveHost On
ProxyRequests off
ProxyPass / http://localhost:3000/
ProxyPassReverse / http://localhost:3000/
</VirtualHost>
cloud.mysite.com
<VirtualHost cloud.mysite.com:80>
ServerName cloud.mysite.com
RewriteEngine on
RewriteCond %{SERVER_NAME} =cloud.mysite.com
RewriteRule ^ https://%{SERVER_NAME}%{REQUEST_URI} [END,QSA,R=permanent]
</VirtualHost>
<VirtualHost cloud.mysite.com:443>
# Basics
ServerName www.cloud.mysite.com
ServerAlias www.cloud.mysite.com
# Next line puts ownCloud at the domain root instead of a /owncloud/ subdirectory (e.g. example.com vs. example.com/owncloud/)
Alias /owncloud "/var/www/owncloud/"
DocumentRoot /var/www/owncloud
# SSTL STUFF GOES HERE
# ownCloud
<Directory /var/www/owncloud/>
Options +FollowSymlinks
AllowOverride All
<IfModule mod_dav.c>
Dav off
</IfModule>
SetEnv HOME /var/www/owncloud
SetEnv HTTP_HOME /var/www/owncloud
</Directory>
</VirtualHost>
SSLStaplingCache shmcb:/var/run/ocsp(128000)
Edit: I resolved this by clearing my cache.
It seems that it should proxy requests to your Node app if it's running on and listening on port 3000 on the same host, or fail if it isn't - but not to proxy requests to the other virtual host.
Make sure that you restarted Apache or made it reload the configuration after you made those changes and that your new config file is where it should be and is enabled.

NodeJS with Apache and directory listing

I am trying to migrate my NodeJS app which works fine from a dedicated server running Nginx to another running Apache2.
Here is my Nginx configuration file
server {
listen 80;
server_name example.com;
root /home/user/myapp;
location / {
proxy_pass http://example.com:9000;
}
location /logs {
autoindex on;
}
}
and here is my Apache2 configuration file
<VirtualHost *:80>
DocumentRoot /home/user/myapp
ProxyRequests off
<Proxy *>
Order deny,allow
Allow from all
</Proxy>
<Location />
ProxyPass http://example.com:9000/
ProxyPassReverse http://example.com:9000/
</Location>
<Directory /home/user/myapp/logs>
Options +Indexes
</Directory>
</VirtualHost>
The NodeJS app works on both http server but I am only able to get the listing directory http://example.com/logs with Nginx but not with Apache2 where NodeJS responds
Cannot GET /logs/
Is something missing in the Apache2 configuration file? Obviously every Apache2 mod are enabled proxy_http proxy and autoindex.
Adding ProxyPass /logs ! works!
<VirtualHost *:80>
DocumentRoot /home/user/myapp
ProxyRequests off
<Proxy *>
Order deny,allow
Allow from all
</Proxy>
ProxyPass /logs !
<Location />
ProxyPass http://example.com:9000/
ProxyPassReverse http://example.com:9000/
</Location>
<Directory /home/user/myapp/logs>
Options +Indexes
</Directory>
</VirtualHost>

AWS EC2 port opened, but still not accessible

I have port TCP 3000 enabled, it even shows enabled under the EC2 security settings.
Although I can not telnet into my server via that port, I'm getting Could not open connection to the host, on port 3000: Connect failed.
I'm running an Ubuntu 12.04 AWS EC2 Micro instance in Oregon.
I'm running apache on the server to host http(s) (80/443) traffic and am trying to host an additional app through port 3000 via nodejs express.
Here is my Apache sites-enabled file:
<VirtualHost *:80>
ServerAdmin name#domain.com
ServerName www.domain.com
ServerAlias www.domain.com
DocumentRoot /var/www/
ProxyRequests off
<Proxy *>
Order deny,allow
Allow from all
</Proxy>
<Location />
ProxyPass http://localhost:80/
ProxyPassReverse http://localhost:80/
</Location>
</VirtualHost>
<VirtualHost *:80>
ServerAdmin name#domain.com
ServerName lobby.domain.com
ServerAlias lobby.domain.com
<Proxy *>
Order deny,allow
Allow from all
</Proxy>
<Location />
ProxyPass http://localhost:3000/
ProxyPassReverse http://lobby.domain.com/
</Location>
</VirtualHost>
This is what you want on your reverse proxy configs:
NameVirtualHost *:80
<VirtualHost *:80>
ServerAdmin name#domain.com
ServerName www.domain.com
ServerAlias www.domain.com
DocumentRoot /var/www/
</VirtualHost>
<VirtualHost *:80>
ServerAdmin name#domain.com
ServerName lobby.domain.com
ServerAlias lobby.domain.com
<Proxy *>
Order deny,allow
Allow from all
</Proxy>
<Location />
ProxyPass http://127.0.0.1:3000/
ProxyPassReverse http://127.0.0.1:3000/
</Location>
</VirtualHost>
Make sure you enable the apache proxy modules, from the command line:
a2enmod proxy
a2enmod proxy_connect
a2enmod proxy_http
a2enmod proxy_balancer
service apache2 restart
Make sure you are binding your application on 0.0.0.0 instead of 127.0.0.1 or localhost. It sounds like your application is not listening to IP addresses outside of the server.
(Also make sure your node.js application is running too)
To listed on 0.0.0.0 you need to so something like this in your application:
var app = connect().use(connect.static('public')).listen(3000, "0.0.0.0");

Resources