Shiny-Server with Apache WebSocket fail - r

I'm new to servers. I installed an Apache web server on Ubuntu 20.04, with and secured the connection with Let's Encrypt. Then I set up a Shiny server (latest Version) and set up the following forwarding in Apache (according to the template).
<Proxy *>
Allow from localhost
</Proxy>
RedirectMatch permanent ^/app$ /app/
RewriteEngine on
RewriteCond %{HTTP:Upgrade} =websocket
RewriteRule /app/(.*) ws://localhost:3838/$1 [P,L]
RewriteCond %{HTTP:Upgrade} !=websocket
RewriteRule /app/(.*) http://localhost:3838/$1 [P,L]
ProxyPass /app/ http://localhost:3838/
ProxyPassReverse /app/ http://localhost:3838/
Header edit Location ^/ /app/
ProxyRequests Off
I can call up my Shiny-app on my mobile phone as well as on the desktop at home (everything works). In our company network, it loads the website first, but not the interactive parts - and then the entire page turns gray.
Based on research, it appears to be a problem with the websockets and the firewall oft the company. The same app on shinyapps.io works. I can find the following error message in the web browser:
sockjs-0.3.4.min.js:27 WebSocket connection to 'wss://srv.socialthink.net/app/uster-kultur/__sockjs__/n=kNUaoWz4VkbEoGT2f8/464/b_7zv2u0/websocket' failed:
I found a similar description of the problem, but no workaround to fix the problem.
I don't know how to continue looking, are there any ideas?

Related

The web application does not display using apache server in linux

I am trying to create a web application using dotnet 3.1 and httpd 2.4 with a proxy server but no mater what how the configuration files are the web application is not displayed.
I am using a Fabian with rhel 7.
The following are the configuration file located in the folder /etc/httpd/conf.d/,
<VirtualHost *:80>
ServerName 22.xx.xxx.xx
ProxyPreserveHost On
ProxyPass / http://127.0.0.1:5000/
ProxyPassReverse / http://127.0.0.1:5000/
RewriteEngine on
RewriteCond %{HTTP:UPGRADE} ^WebSocket$ [NC]
RewriteCond %{HTTP:CONNECTION} Upgrade$ [NC]
RewriteRule /(.*) ws://127.0.0.1:5000/$1 [P]
ErrorLog /var/log/httpd/netcore-error.log
CustomLog /var/log/httpd/netcore-access.log common
</VirtualHost>
My service file located at /etc/systemd/system and is as follows, i hade ensure that the location of the dotnet location is as follows as it was not installed in the standard location. Additionally the root user has been given all required permission
[Unit]
Description=ASP .NET Web Application
[Service]
WorkingDirectory=/var/netcore/publish
ExecStart=/opt/rh/rh-dotnet31/usr/bin/dotnet /var/netcore/publish/Test.dll
Restart=always
RestartSec=10
SyslogIdentifier=netcore-demo
User=root
Environment=ASPNETCORE_ENVIRONMENT=Production
[Install]
WantedBy=multi-user.target
Additional info:
-The error log at location /var/log/httpd/netcore-error.log displays no errors but I no the server has atleast received a request from the following log in the access log
-The access log only shows the following 22.xx.xxx.xxx -- [Date and Time] "GET /HTTP/1.1" 307 -
I have turned of the firewalld.service and configured the IPtable.
When I use curl, there is no response.
Dotnet is listening in port 5000 and 5001, not sure why?
Apache is listening in port 80
When run the application from with dotnet command it seem to work, there does not seem to a problem with the application.
Have tried without specifying the server name and still had no change
Any help would be appreciated as have been stuck on this problem for 2 weeks now.
Just an update - turns out it was a problem with the code/configuration. I think it was called launchsetting.json file, which forcefully made the connection a HTTPS and forward it to the wrong port. Just had to remove that section and all was good.

Cannot get access https and non-www redirect to testing httpd

I have problem cannot get https and non-www redirect to testing httpd. What should i do? The problem is
I cannot access to https eventhough the certificate created successfully
Why when i tried to access https://www works directly to my exact folder but non www direct to testing httpd?
What's the different between www and non-www? There is big different www and non-www about anything or not?
This is my vhost
<VirtualHost *:80>
ServerName test.com
DocumentRoot /var/www/html/public
<Directory /var/www/html/public>
AllowOverride All
</Directory>
RewriteEngine on
RewriteCond %{SERVER_NAME} =test.com [OR]
RewriteCond %{SERVER_NAME} =www.test.com
RewriteRule ^ https://%{SERVER_NAME}%{REQUEST_URI} [END,NE,R=permanent]
</VirtualHost>
I tried rerun the certbot, I choosed :
1: Attempt to reinstall this existing certificate
2: Redirect - Make all requests redirect to secure HTTPS access. Choose this for new sites, or if you're confident your site works on HTTPS. You can undo this change by editing your web server's configuration.
but i got an error
Failed redirect for test.com
Unable to set enhancement redirect for test.com

Setup Centrifugo server with apache virtual host and ssl

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

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 a URL to another URL in Lighthouse/Wordpress

Previously I had a website implemented as a single page application on S3, and it had a page pointing to a list of tools. The URL for this list was: example.com/tool/<tool-name>
To expand the features of my website, I redid the DNS so that this old site is now sitting on a subdomain: tools.example.com/tool/<tool-name> (the new site, that is, example.com, is now on Lighthouse/Wordpress).
As there are still a bunch of links around the web referencing URLs in the tool list of the old site, I would like to write a redirect on Bitnami.
I've already asked for help on this and was told to do the following, but the redirect still doesn't seem to work when I go to example.com/tool/<tool-name>:
Modify /opt/bitnami/apps/wordpress/conf/httpd-app.conf by adding the following rule to the bottom of the file:
RewriteEngine on
RewriteCond %{REQUEST_URI} ^/tool/(.*)$
RewriteRule ^(.*)$ https://tools.example.com/tool/$1 [P,L]
sudo /opt/bitnami/ctlscript.sh apache restart
Is this pattern correct, or am I writing to the right file?
EDIT
I changed the redirect code above slightly to reflect feedback in the comments. It is redirecting to https not http and I changed the last bit of code to [P,L] from [R=301,L]
I just tested this change in the Bitnami solution and it worked properly, can you try it?
Remove the changes from the /opt/bitnami/apps/wordpress/conf/httpd-app.conf file
Edit the /opt/bitnami/apache2/conf/bitnami/bitnami.conf file and include the Rewrite* lines the VirtualHost of the port 80
...
<VirtualHost _default_:80>
DocumentRoot "/opt/bitnami/apache2/htdocs"
RewriteEngine on
RewriteCond %{REQUEST_URI} ^/tool/(.*)$
RewriteRule ^(.*)$ http://google.com [P,L]
...
You can also add those lines in the VirtualHost block of the port 443 in the same file.
Restart Apache
sudo /opt/bitnami/ctlscript.sh restart apache
As you can see, in my example, Apache is redirecting to google.com but you can redirect to any URL.

Resources