cPanel Deployment: my app.js is exposed for everyone to see - mysql

I've developed a tiny app in a hosted server via cPanel, by using node js with express and mysql.
so when the app is running via node or forever, it is accessible only when I add the port number in the url. but when the url is without the port, it goes to an Index of the files in the folder of the subdomain. and everyone can view the app.js file including the password to mysql and user name etc...
I thought js files are not accessible or viewable to the client??
what am i doing wrong?

Create ".htaccess" file in the root of your project with following content
RewriteEngine On
RewriteRule ^$ http://127.0.0.1:XXXX/ [P,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ http://127.0.0.1:XXXX/$1 [P,L]
Where the "XXXX" is the port, that you're using.

Related

htaccess , can't access homepage

I'm trying to set locally a project that run on the web on a NGIX server. This is the htaccess i have downloaded:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /~sitename/
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /~sitename/index.php [L]
</IfModule>
I'm trying to run it locally on an Apache server(on mamp) . It have placed the project in a folder on the server root:
http://localhost/sitename/
But i get a blank page.
I can access a specific internal page (and only that one) if i remove the tilde
~
Even without the tilde, i can't access the homepage of the project.
So what i'm doing wrong?
How the tilde works in this context ?
EDIT
my mod_rewrite is loaded/enabled

Restrict access to local address only in the server

I have multiple web application systems in the server and can be accessible through internet using 122.0.0.1 . I want to access one system only in localhost/network without internet connection using 192.0.0.0.
example:
122.0.0.0/abc
122.0.0.0/def
122.0.0.0/ghi
can access through internet. but i dont want to access
122.0.0.0/abc through internet. i want to access it using 196.0.0.0/abc online through LAN.
Is this possible? then how?
Thank you.
In your .htaccess file, you can add these lines to only allow specific ip addresses:
Order Deny,Allow
Deny from all
Allow from YourIPAdress
You could also use this method, include this in your .htaccess or virtual host config file:
Mentioned here: https://stackoverflow.com/a/23325758/1993548
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{REMOTE_ADDR} xxx\.xxx\.xxx\.xxx [OR]
RewriteCond %{REMOTE_ADDR} xxx\.xxx\.xxx\.xxy [OR]
RewriteCond %{REMOTE_ADDR} xxx\.xxx\.xxx\.xxz
RewriteRule .* - [L] #do notthing
#if we are here, the IP is not in the allowed list, redirect
RewriteCond %{REQUEST_URI} !/maintenance.html$ [NC]
RewriteCond %{REQUEST_URI} !\.(jpe?g?|png|gif) [NC]
RewriteRule .* /maintenance.html [R=302,L]
</IfModule>

Laravel project deployment to live server from local development environment

I'm new to laravel. It's really good application. I developed web application using laravel docs. But the problem is how to deploy it on live server.
In local development environment we use "php artisan serve" command and can access project from http://localhost:8000.
But what should be proper way to run it on live domain. Please don't suggest me something like copy htaccess to root directory and rename server.php to index.php etc.
I will suggest you to watch video from Youtube videos : Move Laravel to Live
This video help you to install to server ; after installing you may even just ise composer or by copying files to server you can run your project in your live server.
Just be sure you installed laravel .
Of problem exists please let me know.
This .htaccess file will point to public/index.php file
DirectoryIndex public/index.php <IfModule mod_rewrite.c><IfModule mod_negotiation.c>Options -MultiViews</IfModule>
RewriteEngine On
# Redirect Trailing Slashes If Not A Folder...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)/$ /$1 [L,R=301]
# Handle Front Controller...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ public/index.php [L]
# Handle Authorization Header
RewriteCond %{HTTP:Authorization} .
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]</IfModule>

Yii2 deployment on Hostgator Cpanel VPS server not working

I have a domain say abcdefgh.com hosted on Hostgator Cpanel VPS Server. It has a folder inside public_html/abcdefgh.com.
Below are the images of deploying my yii2 website but I am unable to get the result on website.
I had previously deployed the Yii2 applications on shared hosting the same way copy pasting the folder, but here in VPS server, I am curious to know what is wrong in this?
1. Hostgator Cpanel VPS Server Deployment
2. Output
3. Server Error Log
Mon Apr 17 22:48:01.706049 2017] [autoindex:error] [pid 32221] [client 117.208.9.75:49825] AH01276:
Cannot serve directory /home/abc/public_html/abcdefgh.com/: No matching DirectoryIndex
(index.php,index.php5,index.php4,index.php3,index.perl,index.pl,index.plx,index.ppl,index.cgi,index.jsp,index.js,index.jp,index.phtml,index.shtml,index.xhtml,index.html,index.htm,index.wml,Default.html,Default.htm,default.html,default.htm,home.html,home.htm) found, and server-generated directory index forbidden by Options directive
.htaccess file
Options -Indexes
# Rewrite engine
RewriteEngine On
# condition with escaping special chars
RewriteCond $1 !^(index\.php|robots\.txt|favicon\.ico)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ ./index.php/$1 [L,QSA]
Delete this from the .htaccess file:
Options -Indexes
Save file and try again!

.htaccess remove .html

I realize there is another post about how to remove .html but it is not working for me so I am trying to understand a little better how this process works.
I have fatcow for my hosting service. I downloaded the .htaccess from fatcow and it downloaded at a .htm file. I inserted this code via notepad.
<IfModule mod_rewrite.c>
Options +FollowSymLinks
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_URI} !(\.[a-zA-Z0-9]{1,5}|/|#(.*))$
RewriteRule ^(.*)$ $1/ [R=301,L]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.html -f
RewriteRule ^([^\.]+)/$ $1.html
</IfModule>
I saved the file as .htaccess and uploaded it to my root folder on fatcow. It is now saved in my root folder as .htaccess.txt
What am I doing wrong here to where this is not working?
UPDATE:
I renamed the .htaccess.txt to .htaccess via FTP client. It shows up at .htaccess now but it is still not removing the .html from my urls.
It should be saved as .htaccess, not .htaccess.txt.
It might be named this way because you created the file on Windows. If this is the case, you have two options:
Upload, then rename
Once the file is uploaded to the server, you can most likely rename the file to have the correct name.
Rename, then upload
You can rename it by doing the following in the Command Prompt:
cd C:\Directory\With\File\In\It
rename .htaccess.txt .htaccess
Once that is done, it should be named .htaccess properly, and can be uploaded.