Setup Centrifugo server with apache virtual host and ssl - nginx

I know most people do it backwards (apache to nginx), but the server where this project is hosted has other projects with particular configurations so... it's better to stick with what we have
What I'm trying to accomnplish is migrate an nginx virtual host configuration, for the centrifugo golang messaging server, to apache2.4 from the docs example
This is what I have
#### This part it's commented because the server says it has incorrect syntax
# <Proxy "balancer://centrifugocluster"> {
# Enumerate all upstream servers here, in case you want to clusterize
# BalancerMember http://127.0.0.1:8000 # default host and port, change it if need it
# BalancerMember http://127.0.0.1:8001;
# </Proxy>
# ProxyPass / balancer://centrifugocluster/
<VirtualHost *:80>
ServerName centrifugo.MY_HOSTING.com
Redirect permanent ^(.*) https://centrifugo.MY_HOSTING.com/$1
</VirtualHost>
<IfModule mod_ssl.c>
<VirtualHost *:443>
ServerName centrifugo.MY_HOSTING.com
SSLEngine On
SSLCertificateFile /PATH/TO/CRT/FILE.crt
SSLCertificateKeyFile /PATH/TO/KEY/FILE.key
SSLCertificateChainFile /PATH/TO/CHAIN/FILE.crt
<Location "/connection/">
# Required for websockets
RewriteEngine on
RewriteCond %{HTTP:Upgrade} =websocket [NC]
RewriteCond %{HTTP:Connection} upgrade [NC]
RewriteRule /connection/(.*) http://127.0.0.1:8000/connection/$1 [P,L]
</Location>
<Location "/">
ProxyPass http://127.0.0.1:8000/
ProxyPassReverse http://127.0.0.1:8000/
</Location>
ErrorLog ${APACHE_LOG_DIR}/PATH/SERVER_LOG/FILE.log
CustomLog ${APACHE_LOG_DIR}/PATH/ACCESS_LOG/FILE.log combined
#### This part I'm not sure how to translate it
ErrorDocument 500 "Server Error 500"
ErrorDocument 502 "Server Error 502"
ErrorDocument 503 "Server Error 503"
ErrorDocument 504 "Server Error 504"
</VirtualHost>
</IfModule>
the server has apache2.4 and ubuntu18, the centrifugo config is
{
"secret": "SECRET",
"admin_password": "PASSWORD",
"admin_secret": "ADMIN-SECRET",
"api_key": "API-KEY",
"engine": "memory",
"admin": true,
"debug": true,
"log_level": "debug"
}
current behavior
the url it's redirected to https succesfully, other projects works good with the ssl config
all directories path are checked and correct
but it says 404 page not found
when I try on the browser centrifugo.MY-HOST.com does show this 404 error
when I try with websocat library (from outside the server) websocat ws://centrifugo.MY-HOST.com/connection/websocket it says WebSocketError: Received unexpected status code. Error running
when I try with websocat library (from INSIDE the server, i mean connected by ssh) websocat ws://localhost:8000/connection/websocket it hangs... (waiting for messages I believe)
the centrifugo server it's up and listening port 8000, checked with netstat and supervisor says running
I changed 127.0.0.1 to localhost in the centrifugo config and the virtual host, added documentRoot to the path of the apache project and nothing...
what i'm doing wrong?

Never mind, it was my mistake in supervisor configuration. I had this:
[program:centrifugo]
command=sudo /var/www/centrifugo-server/centrifugo
autostart=true
autorestart=true
stderr_logfile=/var/log/centrifugo.error.log
stdout_logfile=/var/log/centrifugo.output.log
I placed the config file with full path to it and remove the sudo, and it works like a charm
command=/var/www/centrifugo-server/centrifugo --config=/var/www/centrifugo/config.json
I leave it here in case this could help anyone
Anyway if someone knows how to translate the balancer configuration on the virtual host, that part it's still missing, thanks

Related

ASP.NET application not accessible through Apache proxy on Linux

I need to clarify the process of pointing a web domain to a running ASP.NET application on a raspberry pi. The application is developed and ready, and the website is up and running. I have researched multiple posts and can't find anything wrong with my proxy redirect.
Is dotnet blocking the recieved redirect in someway by locking out any external visitors from the application?
Since there are multiple ways of setting up such an environment. Do I need to configure both an XForwarding in my application as well as a ProxyPass in Apache?
I have an SSL via Letsencrypt, protecting the traffic on my website. This worked fine when running a simple HTML/CSS layout. Do I need to acquire a certificate for my application aswell?
Overall the setup is not working, and I'm itching to understand why. Most threads seem to imply its as simple as running the app on port x -> pointing to port x -> success. For me this isn't working...
Through wget I successfully reach my website via both ports (since I redirect HTTP to HTTPS). By entering the localhost:port into browser I can find the application. Why is my proxy not working?
Accessing my website
https://localhost:7199
Apache2 Virtual host
<VirtualHost *:80>
ServerName www.website.com
RedirectPermanent / https://www.website.com
</VirtualHost>
<IfModule mod_ssl.c>
<VirtualHost *:443>
ServerAdmin webmaster#localhost
ServerName www.website.com
ServerAlias www.website.com
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
ProxyRequests Off
ProxyPreserveHost On
ProxyPass / http://localhost:7199/
ProxyPassReverse / http://localhost:7199/
SSLEngine On
SSLCertificateFile /etc/letsencrypt/live/www.website.com/cert.pem
SSLCertificateKeyFile /etc/letsencrypt/live/www.website.com/privkey.pem
Include /etc/letsencrypt/options-ssl-apache.conf
SSLCertificateChainFile /etc/letsencrypt/live/www.website.com/chain.pem
</VirtualHost>
</IfModule>
All and any thoughts are very appreciated. Thanks for reading!

Blazor CSS not found

When I execute my Blazor app on localhost everything is fine. When I upload the compiled code to my final server, the app works but all CSS/JS are missing.
I use Centos 7 + Apache in reverse proxy mode.
My CNF:
<VirtualHost *:*>
RequestHeader set "X-Forwarded-Proto" expr=%{REQUEST_SCHEME}
</VirtualHost>
<VirtualHost *:80>
# Your domain name
ServerName 192.168.5.69
ProxyPreserveHost On
# The IP and port of the JBoss Enterprise Application Platform
# These represent the default values, if your HTTPD is on the same host
# as your JBoss Enterprise Application Platform managed domain or server
ProxyPass / http://localhost:5000/
ProxyPassReverse / http://localhost:5000/
# The location of the HTML files, and access control information
DocumentRoot /var/www/html
RewriteEngine on
RewriteCond %{HTTP:UPGRADE} ^WebSocket$ [NC]
RewriteCond %{HTTP:CONNECTION} Upgrade$ [NC]
RewriteRule /(.*) ws://127.0.0.1:5000/$1 [P]
<Directory /var/www/html>
Options -Indexes
Order allow,deny
Allow from all
</Directory>
</VirtualHost>
On Chrome console I see:
Siti:12 GET http://192.168.5.69/js/JavaScriptInterop.js net::ERR_ABORTED 404 (Not Found)
Siti:11 GET http://192.168.5.69/css/site.css net::ERR_ABORTED 404 (Not Found)
Siti:10 GET http://192.168.5.69/css/font-awesome/font-awesome.min.css net::ERR_ABORTED 404 (Not Found)```

Shiny server running on localhost can't be accessed from web when redirected by apache

Hello dear stackoverflow!
I'm having trouble setting up shiny server and apache2 routing.
Roughly following this guide https://support.rstudio.com/hc/en-us/articles/213733868-Running-Shiny-Server-with-a-Proxy (but with apache2)
I set up shiny to run on my 127.0.0.1:2224 port. Everything works just fine when I open a tunnel and port forward, I see my app on localhost.
I set up pwd and redirection in apache as:
<VirtualHost *:80>
ServerAdmin karin#localhost
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
ProxyPass "/myapp" "http://localhost:2224"
ProxyPassReverse "/myapp" "http://localhost:2224"
<Location /myapp>
AuthType Basic
AuthName "Enter your login name and password"
AuthUserFile /etc/apache2/.htpasswd
Require valid-user
</Location>
And when I open public my.ip/myapp I am prompted to log in, and after doing so I am redirected to local port 2224, yay!
~ however, the app seems to be broken. I can't see any of the resources, images, css - just the plain interface as coded in the app ui.R
I see a plenty of 404 in logs, the shiny server is looking for all these resources on the web, with address my.ip/shared/whatever - but the resources are accessible only through localhost:2224/shared/whatever
...
any idea where I messed up the routing? What privileges are missing, or what to try to be able to access my app without setting up ssh tunnel and port forward?
Thanks a lot for any ideas!
Roughly following this guide https://support.rstudio.com/hc/en-us/articles/213733868-Running-Shiny-Server-with-a-Proxy (but with apache2)
I have had success in using apache2 as a reverse proxy for shiny server when following that guide in detail, in particular the last examples. In your case, you should replace
ProxyPass "/myapp" "http://localhost:2224"
ProxyPassReverse "/myapp" "http://localhost:2224"
with
RedirectMatch permanent ^/myapp$ /myapp/
RewriteEngine on
RewriteCond %{HTTP:Upgrade} =websocket
RewriteRule /myapp/(.*) ws://localhost:2224/$1 [P,L]
RewriteCond %{HTTP:Upgrade} !=websocket
RewriteRule /myapp/(.*) http://localhost:2224/$1 [P,L]
ProxyPass /myapp/ http://localhost:2224/
ProxyPassReverse /myapp/ http://localhost:2224/
Header edit Location ^/ /myapp/
ProxyRequests Off

Redirect http to htps on apache2 vhost behind aws ELB

I have a small problem with redirecting everything from http to https.
Here is the setup of my environment:
The server is a docker host which runs multiple docker containers. I'm trying to access a container that listens on port 9000. so I have a ProxyPass in the vhost file that looks like this:
<VirtualHost *:80>
ProxyPreserveHost On
ServerName subdomain.domain.com
ProxyPass / http://localhost:9000/
ProxyPassReverse / http://localhost:9000/
Redirect / https://subdomain.domain.com/
</VirtualHost>
The SSL Certificate is issued by AWS.
This server is behind a AWS Load Balancer. From the load balancer I have 2 target groups. One is redirecting 80 to 80, and the other 443 to 443.
Right now the https://subdomain.domain.com is throwing 502 bad gateway error.
Could someone have any idea what the issue here might be? Thanks in advance!
Does this help: https://www.namecheap.com/support/knowledgebase/article.aspx/9821/38/redirect-to-https-on-apache?
It seems like you need to redirect permanent.
I've tried adding this to the vhosts file:
RewriteEngine On
RewriteCond %{HTTP:X-Forwarded-Proto} =http
RewriteRule .* https://%{subdomain.domain.com/}%{REQUEST_URI} [L,R=permanent]
as indicated in the aws documentation. It doesn't work, I get an error saying invalid redirect. No idea what the problem is.
Anyone else experienced this problem?

Issu with varnish-ban-manager installation, using vhost in AWS

I've installed varnish-ban-manager (https://github.com/dot2code/varnish-bans-manager) and I'm currently configuring it's DNS name.
The thing is that I've set in Route53 (DNS service in AWS) to use name http:// purge.domain.com / pointing to http:// varnish_server_name.com/. The thing is, if I test with http :// purge.domain .com:9000/ it works normally, but using http: //purge.domain.com/ will send me a "your request cannot be processed" (in a varnish error screen).
Any ideas why this could be happening? I've test this with the ip address of this vm and works perfectly too..
Here's the vhost config file:
<VirtualHost *:80>
ServerName purge.domain.com
ServerAlias purge.domain.com
ProxyPass / http://varnish_server.domain:9200/
ProxyPassReverse / http://purge.domain.com/
# Logging
ErrorLog logs/server-error_log
CustomLog logs/server-access_log combined
</VirtualHost>
Note: i've replaced my real domain for "domain" just in case.
Thanks guys!!
Solved. I've added some lines to vhost:
ServerName http:// purge.comain.com
ProxyPass / http:// varnish_server:9000/
ProxyPassReverse / http:// varnish_server:9000/
ErrorLog logs/purge. cloud-turner.com.ar-error_log
CustomLog logs/purge. cloud-turner.com.ar-access_log combined
And added proxy.conf (/etc/httpd/conf.d/) with this line
ProxyPreserveHost on
And that's it!

Resources