As we know, when we run NodeJS on hosting server and want to hide port like :3000 from the browser address bar, we can set up ngnix or use in .htaccess the rules like
RewriteEngine On
RewriteRule ^$ http://example.com:3000/ [P,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ http://example.com:3000/$1 [P,L]
But what about running NodeJS locally on Windows? Is it possible to hide the port in the browser address bar in this case? I mean without additional server
ps. I run Windows binary 64-bit version of NodeJS on Windows 7
Related
I almost broke my brain while figuring it out and I need some help.
I have a shared hosting, Apache 2.4, example.com and a website running on main domain built in php.
I installed nodejs and it is running on example.com:5000 and it is working well, however I need nodejs to be able to listen to the subdomain app.example.com (and app.domain.com/*)
I have tried so many combinations of following things and none worked out.
Using vhost package for nodejs:
const vhost = require('vhost');
const express = require('express');
const app = express();
****
express()
.use(vhost('app.example.com', require('../widget/app.js').app))
.listen(port)
//it is only listening to the port, and doesn't work for the subdomain
Rewriting .htaccess file and saving it to the root folder or the public folder or the app folder:
variant 1:
RewriteEngine On
RewriteCond %{HTTP_HOST} ^ app.example.com/$
RewriteRule ^(.*)$ http://example.com:50000/$1 [P,L]
Variant 2:
RewriteEngine On
RewriteCond %{SERVER_PORT} ^50000$
RewriteRule ^(.*)$ http://app.example.com/$1 [P,L]
Variant 3:
RewriteEngine On
RewriteRule ^$ http://app.example.com:50000/ [P,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ http://app.example.com:50000/$1 [P,L]
What is the right way to make it happened?
Have a great day!
Hello I'm using open source prerender middleware, as I installed it on CentOS 7 server as follows:
git clone https://github.com/prerender/prerender.git
cd prerender
npm install
The configuration I am using in server.js file is quite simple:
var prerender = require('./lib');
var server = prerender({
chromeLocation: '/usr/bin/google-chrome-stable',
chromeFlags: ['--no-sandbox','--headless', '--disable-gpu', '--remote-debugging-port=9222', '--hide-scrollbars','--disable-setuid-
sandbox' ]
});
server.use(prerender.sendPrerenderHeader());
// server.use(prerender.blockResources());
server.use(prerender.removeScriptTags());
server.use(prerender.httpHeaders());
server.use(require('prerender-memory-cache'))
server.start();
I'm also using the prerender-apache middware along with prerender and angular js app
RequestHeader set X-Prerender-Token "token"
<IfModule mod_proxy_http.c>
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{HTTP_USER_AGENT} Googlebot|Sitemaps|Google-Structured-Data-Testing-Tool|baiduspider|facebookexternalhit|twitterbot|rogerbot|linkedinbot|embedly|quora\ link\ preview|showyoubot|outbrain|pinterest|slackbot|vkShare|W3C_Validator [NC,OR]
RewriteCond %{QUERY_STRING} _escaped_fragment_
RewriteCond %{REQUEST_URI} /(.*)/(.*)/
# Only proxy the request to Prerender if it's a request for HTML
RewriteRule ^(?!.*?(\.js|\.css|\.xml|\.less|\.png|\.jpg|\.jpeg|\.gif|\.pdf|\.doc|\.txt|\.ico|\.rss|\.zip|\.mp3|\.rar|\.exe|\.wmv|\.doc|\.avi|\.ppt|\.mpg|\.mpeg|\.tif|\.wav|\.mov|\.psd|\.ai|\.xls|\.mp4|\.m4a|\.swf|\.dat|\.dmg|\.iso|\.flv|\.m4v|\.torrent|\.ttf|\.woff))(.*) http://some.ip:3000/https://%{HTTP_HOST}/$2 [P,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{HTTP_USER_AGENT} Googlebot|Sitemaps|Google-Structured-Data-Testing-Tool|baiduspider|facebookexternalhit|twitterbot|rogerbot|linkedinbot|embedly|quora\ link\ preview|showyoubot|outbrain|pinterest|slackbot|vkShare|W3C_Validator [NC,OR]
RewriteCond %{QUERY_STRING} _escaped_fragment_
RewriteCond %{REQUEST_URI} ^/rootDirectory/
# Only proxy the request to Prerender if it's a request for HTML
#RewriteRule ^(.*) http:/some.ip:3000/https://%{HTTP_HOST} [P,L]
</IfModule>
So first I was trying to run it with forever.js with following command in prerender folder:
forever start server.js
It works properly for a few hours and then a problem arises that I can't figure out why it occurred. Many chrome sessions start to be created and the server RAM starts to decrease until the server stops, I read that the flag: '--no-sandbox causes this problem and I have removed it, but then I got another problem when I start server.js forever I got :
Starting Prerender
Starting Chrome
Prerender server accepting requests on port 3000
Chrome connection closed... restarting Chrome
Chrome died immediately after restart... stopping Prerender
error: Forever detected script exited with code: 0
I'm using
node.js v12.14.0
Google Chrome 85.0.4183.102
I'll be grateful if someone could help thanks.
I'm using a shared hosting service that always has Apache web server running, so I can't run my Node.js application directly on port 80. Instead, as I've been told by my host, I need to use .htaccess to redirect incoming requests to my Node.js app, which is currently running on port 50000. Here's the .htaccess file they told me to use:
RewriteEngine On
RewriteRule ^$ http://127.0.0.1:50000 [P,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ http://127.0.0.1:50000/$1 [P,L]
This works well enough, except that when I try to go to mydomain.com, the Node app is seeing a request for /index.php. The tech support for my host seems to be as confused as I am. If I go to mydomain.com/test then Node.js app sees /test, so Apache seems to only be adding index.php on the root URL. Could this be an Apache caching issue from someone accessing the URL prior to the .htaccess file and Node.js app being set up?
UPDATE
At this point, no one seems to have a clue what is going on, so I'm just going to add an 'index.php' route to my Node app. Thanks to everyone who took a look and tried to help out.
You might have DirectoryIndex set up for index.php in apache conf file which may be the reason you are getting index.php automatically, what you can do is to set DirectoryIndex to some filename which may not exist or if it is apache 2.4 use DirectoryIndex disabled in your .htaccess.
This is actually what you are going to want to put in your /public_html directory
In the .htaccess file in the code below you will see
http://127.0.0.1:50000
(50000) is the port you are sending it too. There are 2 spots where you make that update.
Also update the example.com
RewriteEngine On
RewriteCond %{HTTP_HOST} ^example\.com [NC]
RewriteCond %{SERVER_PORT} 80
RewriteRule ^(.*)$ https://example.com/$1 [R,L]
DirectoryIndex disabled
RewriteEngine On
RewriteRule ^$ http://127.0.0.1:50000 / [P,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ http://127.0.0.1:50000 /$1 [P,L]
This is a specific configuration for an apache server with nodejs.
I'm currently developing some websites with Node.js, but when I take it offline for maintenance etc. it shows me a 503 (an ugly one...)
It's on a host where I can run Node.js on given port (doh) and I need to place an htaccess file with a redirect to that port in the apache folder.
I've been googling a while, and I can't find it... Help?
.htaccess:
RewriteRule ^$ http://127.0.0.1:*portno*/ [P,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ http://127.0.0.1:*portno*/$1 [P,L]
It's a shared hosting account with SSH access.
Apache Version 2.2.29
cPanel Version 11.48.0 (build 13)
So I have a ridiculous problem that the hosting company cannot seem to take care of by itself. I have a website on a windows server that has ISAPI Rewrite 3 running to allow me to use .htaccess files for wordpress. But I noticed that the
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
statements are not working. They are just ignored. Is this a configuration issue? In the mean time I have the site up and running with this clever line that I stole from somewhere
RewriteCond %{REQUEST_URI} (/[^.]*|\.(html?|php))$ [NC]
The problem is that using this line I cannot access an actual directory that exists. Ex. /wp-admin/ so if I want to make changes in the admin area I have to enable that line that restricts by IP make the changes and then turn off that line. Utterly ridiculous.
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_URI} (/[^.]*|\.(html?|php))$ [NC]
#disallow or allow just my IP address
#RewriteCond %{REMOTE_HOST} !1.2.3.4
RewriteRule .* /index.php [L]
Any solutions so that I can still access directories that exist without using the %{REQUEST_FILENAME}?
Well .. I have Helicon ISAPI_Rewrite v3 running on IIS 6 (and had it on IIS 7 2 years ago) .. and these instructions actually work fine:
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
It may not work that well if part of the URL is virtual folder / application .. but it works fine with real files and folders. Try these instead (should work exactly the same if no virtual stuff involved):
RewriteCond %{DOCUMENT_ROOT}%{REQUEST_URI} !-f
RewriteCond %{DOCUMENT_ROOT}%{REQUEST_URI} !-d