Pointing .htacees to node server that uses SSL configurations - node.js

I am using the following configurations in .htacess file
# RewriteRule ^(.*)?$ http://127.0.0.1:3001/$1 [P,L]
# RewriteRule ^(.*)?$ https://127.0.0.1:3001/$1 [P,L]
when I add SSL configurations and use https module in the node server the URL returns 503 services not found but works fine when I remove SSL and use http module.

Problem fixed by removing
RewriteRule ^(.*)?$ http://127.0.0.1:3001/$1 [P,L]

Related

HTTP 500 Error Ionos with TYPO3 because of Rewrite Non-www to www in .htaccess

I got the following code in my .htaccess
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{HTTPS} !=on
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
RewriteCond %{HTTP_HOST} ^example.de [NC]
RewriteRule ^(.*)$ https://www.example.de/$1 [L,R=301,NC]
</IfModule>
If I call the url without "www" everything works fine! But with "www" it ends with http 500 error!
So on my development Server erverything works fine, with and without www!
On Ionos Server I can do what I want I guess.
I got https://www.expample.de in my Siteconfiguration of TYPO3 9.5 but it doesnt matter. Does anybody know a solution?
I think this is maybe not a .htaccess problem?!
Fix for IONOS hosted TYPO3 installations where adding www to the URL gives a 500 error:
Go to your install tool, /typo3/install.php should be accessible with www in the URL.
Go to Settings and open Configure Installation-Wide Options
Under [SYS][trustedHostsPattern] where SERVER_NAME is set by default, add your domain, for example. .*\.domain\.com (There are other examples given in the install tool).
Save these changes, the website is now accessible with www.

Apache redirect of a node app to a folder with .htaccess

I have a shared hosting. The domain mydomain.com points to /home/myuser/www, and I have my app in /home/myuser/www/myapp. I want to access to my node app via mydomain.com, and I think have to redirect via .htaccess file. All my assets are built to /dist folder in the app, with server.js in /dist/server.js.
I have this configuration, but it fails:
RewriteEngine On
RewriteRule ^/myapp$ http://127.0.0.1:4000/ [P,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^/myapp/(.*)$ http://127.0.0.1:4000/$1 [P,L]
In local my app is happily running in http://localhost:4000; how should I configure the /home/myuser/www/.htaccess file?
You can use the mod_proxy for the same. (It is enabled by default in apache, but make sure it is).
The rule will be
ProxyPass / http://127.0.0.1:4000/
ProxyPassReverse / http://127.0.0.1:4000/
The above rule is passing all the root request to internal port of your Node JS app with out user knowing about it (different from a rewrite)
Do restart the apache server for the effects to be seen.
You can also refer the blog post for the same

htaccess proxy to node app

I am trying to proxy subdomain to node application which is running on port 3000. It proxies requests to files e.g subdomain.domain.com/jquery.js. It works fine and shows file served by node. But when I try to access the root of subdomain then I guess apache tries to find index.php and fails with message Cannot GET /index.php. How can I make it work so it will serve whatever provided by node app?
my htaccess
RewriteEngine On
RewriteRule ^(.*)$ http://127.0.0.1:3000/$1 [P,L]
RewriteRule ^$ http://127.0.0.1:3000/ [P,L]
RewriteEngine On
DirectoryIndex disabled
worked out

AWS ELB Redirect HTTP to HTTPS without index.php

I am using AWS Elastic Beanstalk to host my website with Load Balancer over some EC2 instances.
I am using OctoberCMS (a flavour of laravel as a framework)
I have setup SSL Certificate over my ELB via AWS Certificate Manager and all is working fine.
But there is a problem.
I want to redirect HTTP to HTTPS.
According to AWS, I got a small .htaccess snippet to do the job:
Redirect to HTTPS
RewriteCond %{HTTP:X-Forwarded-Proto} =http
RewriteRule . https://%{HTTP:Host}%{REQUEST_URI} [L,R=permanent]
However, when a user gets to http://mywebsitesite.com it takes them to https://mywebsitesite.com/index.php hence they start browsing in the manner of https://mywebsitesite.com/index.php/someresource.
Also if you go to http://mywebsitesite.com/someresource, you are redirected back to https://mywebsitesite.com/index.php.
This is not a good experience and I know someone must have encountered this before and is able to redirect to resource properly and remove the index.php
My ELB listener is configured by default to 80 --> 80 and 443 --> 80
Note: I am not encountering a redirect loop.
I'll preface this answer with saying that this is code from the Tomcat Elastic Beanstalk but I believe that it should still work.
I had in my configuration code file:
RewriteEngine On
RewriteCond %{HTTP:X-Forwarded-Proto} !https
RewriteRule ^(.*)$ https://%{HTTP_HOST}$1 [R,L]
This was part of a .ebextensions file that configured the Apache proxy which, in my case, was in front of Tomcat.
You can add the following line in .htaccess to hide the index.php from the url after the redirect configuration.
RewriteRule ^(.*)$ /index.php?/$1 [L]

AWS Elasticbeanstalk single instance Force SSL Redirect loop

I'm having issues by forcing ssl. I'm using codeigniter and deployed it in AWS single instance with elasticbeanstalk. My htaccess rules below:
RewriteEngine On
RewriteCond %{HTTPS} off
RewriteRule !/status https://%{SERVER_NAME}%{REQUEST_URI} [L,R]
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /index.php/$1 [L]
But browser gets in a redirect loop. Whatever i tried didnt solve this problem.
As I mentioned in my comment:
in the ssl.conf every call from port 443 is "proxyed" to port 80, so you never get https = on.
I did some tests and I found out that the ProxyPass directive in ssl.conf does not simply redirect every request from port 443 to localhost:80, but basically repeats the request to Apache from scratch, through the port 80 (at least, that's what I understood).
I checked the value of $_SERVER and found out that HTTP_X_FORWARDED_FOR, HTTP_X_FORWARDED_HOST and HTTP_X_FORWARDED_SERVER are set during a HTTPS request (but they are NOT set during a HTTP request), meanwhile SERVER_ADDR and REMOTE_ADDR are set to 127.0.0.1 during a HTTPS request (but they are set to different values for HTTP requests).
I assume you can easily check if your request was plain HTTP with something like this (check the syntax, I'm rubbish with Apache):
RewriteCond %{ENV:HTTP_X_FORWARDED_SERVER} !^$
or
RewriteCond %{ENV:SERVER_ADDR} !^127\.0\.0\.1
BEWARE: I couldn't find any reference in AWS documentation, it's just an empiric result... they can easily change this behavior!
Happy coding! :)
I run into the same problem. Here is what worked for me:
RewriteCond %{SERVER_PORT} !=443
RewriteCond %{SERVER_ADDR} !^127\.0\.0\.1
RewriteRule (.*) https://%{SERVER_NAME}/$1 [L]
Here is the official way. Found in AWS docs.
RewriteEngine On
RewriteCond %{HTTP:X-Forwarded-Proto} !https
RewriteCond %{HTTP_USER_AGENT} !ELB-HealthChecker
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI}
Sources
https://docs.aws.amazon.com/elasticbeanstalk/latest/dg/configuring-https-httpredirect.html
https://github.com/awsdocs/elastic-beanstalk-samples/blob/master/configuration-files/aws-provided/security-configuration/https-redirect/php/https-redirect-php.config
I believe (give your exception for /status) that you are using the "Load-balancing, Autoscaling Environment" which means you have an Elastic Load Balancer in the middle.
If you setup your environment with Elastic Load Balancing, than what may be happening is if the Elastic Load Balancer (ELB) is using (serving) secure content (HTTPS).
However, if the traffic between the ELB and the EC2 Instances is unsecure, your code will always detect an unsecure connection because the EC2 client is actually the ELB, not the end user (think of the ELB as a proxy).
Side note, I'm not sure how the SERVER_NAME variable will work with an ELB in the middle.
That said, if your intention was for a single-instance, non-load balanced environment, you can "turn off" the load balancer (possible since July 2013). (see ref #3)
Reference: http://docs.aws.amazon.com/elasticbeanstalk/latest/dg/using-features.managing.elb.html
http://docs.aws.amazon.com/elasticbeanstalk/latest/dg/using-features-managing-env-types.html
Elastic Beanstalk without Elastic Load Balancer
This is the right way:
RewriteEngine on
RewriteCond %{HTTP:X-Forwarded-Proto} !https
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

Resources