The web application does not display using apache server in linux - asp.net

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.

Related

Shiny-Server with Apache WebSocket fail

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?

asp.net core apache Internal Server Error

I am trying to deploy an ASP.net Core 3.1 app to a server with apache2 installed. I have created the following virtualhost:
<IfModule mod_ssl.c>
<VirtualHost *:443>
ProxyPreserveHost On
ProxyPass / https://127.0.0.1:5001/
ProxyPassReverse / https://127.0.0.1:5001/
#ServerAdmin mail#mail.com
ServerName xx.app
ServerAlias www.xx.app
ErrorLog ${APACHE_LOG_DIR}xx-error.log
CustomLog ${APACHE_LOG_DIR}xx-access.log common
SSLCertificateFile /etc/letsencrypt/live/xx.app/fullchain.pem
SSLCertificateKeyFile /etc/letsencrypt/live/xx.app/privkey.pem
Include /etc/letsencrypt/options-ssl-apache.conf
</VirtualHost>
</IfModule>
when i run the application (using dotnet .dll), i get the following message:
Hosting environment: Production
Content root path: /home/cv/web/publish
Now listening on: http://localhost:5000
Now listening on: https://localhost:5001
Application started. Press Ctrl+C to shut down.
Then when i try to browse the app I get the following error:
Internal Server Error
The server encountered an internal error or misconfiguration and was unable to complete your request.
Please contact the server administrator at [no address given] to inform them of the time this error occurred, and the actions you performed just before this error.
More information about this error may be available in the server error log.
When I view the logs the only thing that I find is:
AH01144: No protocol handler was valid for the URL / (scheme 'http'). If you are using a DSO version of mod_proxy, make sure the proxy submodules are included in the configuration using LoadModule.
I have tried to enable the mods proxy_http, http and it didn't fix the issue.
Thanks in advance!
The issue was that the virtual host needed these two lines at the start:
LoadModule proxy_module modules/mod_proxy.so
LoadModule proxy_http_module modules/mod_proxy_http.so
and these lines at the virtualhost *443:
SSLProxyEngine on
SSLProxyVerify none
SSLProxyCheckPeerCN off
SSLProxyCheckPeerName off
SSLProxyCheckPeerExpire off

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 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?

Resources