React.js and folder access denied for user - reactjs

I don't know if there is any type of post like this one here on StackOverflow but I just wonder how do I make so people who visit my site can't get access to "ip/folder names".
If it for some help I use react.js and I know some people use the .htaccess file but it doesn't work for me or maybe because I do it wrong. I am kind of new of this sort of things.
Error page
I want actually do so if people visit some page/folder or file they come to a page it says "404 page error"

To be able to use .htaccess files depends on how the apache configuration is done on your server. A .htaccess file needs permission to be able to override standard web configurations. If you want to set that up and use them you can try:
sudo vim /etc/apache2/sites-available/default
Then make sure the line AllowOverride has the value All. That means local .htaccees files are allowed to override.
<Directory /var/www/>
...
AllowOverride All
...
</Directory>
Save and restart the service
sudo service apache2 restart
In your .htaccess file you can add following for creating an custom error page
ErrorDocument 404 /my_custom_error_page.html
Here you can read more about writing .htaccess files
https://www.digitalocean.com/community/tutorials/how-to-use-the-htaccess-file
Hope that helped a bit.

Related

Apache localhost authentication

I am trying to setup up basic authentication to a folder on my localhost running apache. Currently the app runs fine without authentication. I have setup a virtual host so I can access my application through dev.myapp.com
The code I add to my .htaccess file to force authentication is:
<Directory "/Users/myusername/Sites/dev.myapp.com">
AuthType Basic
AuthName Test
AuthBasicProvider file
AuthUserFile /etc/apache_users
Require valid-user
</Directory>
I have created a user.
When I type dev.myapp.com into the browser I get an internal server error. I am fairly new to apache. A point in the right direction would be appreciated.
Thanks.
First off, using .htaccess is a bit slower and requires that you have set the AllowOverride directive accordingly. It is recommended that you instead use httpd.conf to establish basic authentication. The Apache documentation explains all of this so check out this link http://httpd.apache.org/docs/2.2/howto/auth.html.
Regardless, I think I see the error. Your <Directory> tag looks a little odd. I understand the name of your site is dev.my.app.com but is that the actual name of the folder where the site dev.myapp.com points to on your server? Your httpd.conf file should have an entry like this:
<VirtualHost *>
DocumentRoot "document/root/path"
Other directives here
</VirtualHost>
The DocumentRoot is where Apache directs all incoming web traffic. If you are trying to establish authentication for your entire site, the value of DocumentRoot is most likely what you would want in your Directory tag ... making it <Directory /document/root/path>.
To locate httpd.conf look in in /etc/apache2/. Make sure to restart your server after you change the file (sudo /etc/init.d/apache2 restart). Hope that helps, please update if you haven't already resolved the problem.

Vagrant 403 Forbidden

I've been running Vagrant successfully for about a week. Last night I ran vagrant reload and now I can no longer access my sites.
VirtualBox version 4.2.16
Vagrant version 1.2.7
My Vagrantfile and bootstrap.sh: https://github.com/kriskd/vagrant-settings
Running on Mac
My files live at /vagrant/Sites. At first my "welcome page" which lives at /vagrant/Sites rendered at
http://localhost:4567/
All my projects are folders under Sites. For example, /vagrant/Sites/test won't render index.html. I get the following
Forbidden
You don't have permission to access / on this server.
Apache/2.4.6 (Ubuntu) Server at localhost Port 4567
The vhost looks like:
<VirtualHost *:80>
DocumentRoot "/vagrant/Sites/test"
ServerName test
<Directory "/vagrant/Sites/test">
AllowOverride All
</Directory>
</VirtualHost>
The vhosts are owned by root. My project files are owned by vagrant and chmod'ed 0777.
After no success, I did a full vagrant destroy followed by vagrant up and then the localhost host welcome page stopped rendering as well with the forbidden error.
My hunch is that this is not a vagrant issue at all but solely an Apache configuration glitch. There are a few things I can think to check.
First, obviously, is to confirm that the user that apache is running under has read and execute permissions for the DocumentRoot folder.
Since you mentioned Apache 2.4, there have been changes in the configs from 2.2. Make sure your Allow from all statements now read Require all granted. (If you were still on 2.2, you'd want to make sure they said Allow from all instead of Deny from all.) In either case, you can set this in each <VirtualHost> individually, or set a default in your <Directory /> block of the main httpd.conf file.
Getting more obscure, you could check for selinux, although I'm pretty sure this isn't present in Ubuntu by default. (It is in CentOS, for example.)
This is solved and in the end came down to some very simple things.
Use "Require All granted" instead of "Allow from All"
Put each websites' content at the same level namely /vagrant/Sites/default, /vagrant/Sites/test, /vagrant/Sites/real-site
Add .conf extension to vhost names such as test.conf and real-site.conf
Add AllowOverride All to vhosts to respect sites' .htaccess file (I realize that was in my original post, it got lost as I tried to solve this)
All very basic things that eluded me for a better part of a week. I hope this can help someone else.
I had the same problem when changing the DocumentRoot.
Since you've changed your DocumentRoot to "/any/path/foo/bar", make sure you have the permissions set on "apache2.conf" for this path.
Search for:
<Directory /any/path/foo/bar>
in apache2.conf
And add a new block like this:
<Directory /any/path/foo/bar>
Options Indexes FollowSymLinks
AllowOverride All
Require all granted
</Directory>
And my guess is that everything is gonna be fine!
cd /etc/apache2/sites-available
for file in `ls *`; do sed 's/\(.*<\/Directory.*>\)/Require\ all\ granted\n\1/' $file > $file.new;mv $file.new $file ; done;
because it worked before, I would not waste time on fix file by file

Can't access files in a subdirectory using Apache server

I have an Apache 2.2.21 server installed on my Windows 7 machine.
My site is up and my scripts from /scripts subdirectory are working but when I try to load icons from /icons I get a 403 forbidden error.
I've already added this to my httpd.conf file:
<Directory "c:/wamp/www/icons/">
Options Indexes FollowSymLinks
Order Deny,Allow
Deny from all
Allow from 127.0.0.1
</Directory>
Still no effect. So the question is: how can I access files in my /icons subfolder?
P.S.: Using /images subdirectory worked out just fine but the question still remains.
I figured out that /icons/ was included as an alias for some other directory. For me, configuration file was located at:
C:\wamp\bin\apache\apache2.2.21\conf\extra\httpd-autoindex.conf
I had to comment out this line:
Alias /icons/ "c:/Apache22/icons/"
Have you checked the Windows permissions on the /icons directory, and made sure that the Apache user can read that directory? Is there possibly an .htaccess file in the picture?
Edit: Okay, so it's not permissions. My next guess is this: your config above says "everyone is forbidden access except when they're coming from 127.0.0.1". But you're on Windows 7. Windows 7 tries to be helpful and modern - and often tries accessing via IPv6 first. So you might show up as coming from ::1, which is probably failing to match 127.0.0.1. Try turning off IPv6 or adding an Allow from ::1 directive.
Ok so if your httpd.conf doesn't do anyhting you should restart apache. Any changes done to documents have to be restarted so Apache can "Refresh".
<Directory "c:/wamp/www/icons/">
Options Indexes FollowSymLinks
Order Deny,Allow
Deny from all
Allow from 127.0.0.1
</Directory>
So above this is your code. It basically says in line 4 that Apache should deny connection from all incoming connections connections to the /icons/folder.
Also on line 5 it says to allow incoming connections from only 127.0.0.1 or localhost. So basically the server has access to it!
If changing it doesn't work you should look in .htaccess. Another option is just to copy the Code from a folder that works and paste it and just change the paste from EX:
"C:/WAMP/www/images/" to "C:/WAMP/www/icons".

htaccess set specific file to download only

I'm working on developing a javascript framework and I don't want anyone to be able to link to the "nightly build" .js file directly on the server.
Based on my research from google, here's what I have in my htaccess:
<FilesMatch /development/flanvas/flanvas.js>
ForceType applicaton/octet-stream
</FilesMatch>
And I've also tried putting a .htaccess file in /development/flanvas/ and adding:
AddType applicaton/octet-stream.js
Neither have worked so far :(
*edit
I suppose if a user really wanted to snag this, they could curl/ajax it. Is it advised to have the .htaccess check the HTTP_REFERER instead? This could potentially get two birds with one line..
Is the root of your server really the DocumentRoot for the website?
i.e. is /development/flanvas/flanvas.js the absolute path to the JS file on your machine?
I would try
<FilesMatch ^(.*)flanvas\.js$>
ForceType applicaton/octet-stream
</FilesMatch>
or
<FilesMatch /path/to/documentroot/development/flanvas/flanvas.js>
ForceType applicaton/octet-stream
</FilesMatch>
Hope this helps
This is the person that asked the question. Apparently I have no idea what account I posted this question under, but once I figure it out I'll come back and checkmark your question is it 100% worked.
Ended up using:
# Force download for flanvas.js
<FilesMatch ^(.*)flanvas\.js$>
ForceType applicaton/octet-stream
</FilesMatch>

How to install cakephp on localhost?

I wanna to know how to install cakephp on localhost?
Please explain me.
I usually make an apache and mysql installation on a linuxbox. I can use windows too, however I do not recommend it ;)
So, I usually make a new entry into the /etc/hosts file to make a sitename available to cakephp.
127.0.0.1 localhost caketest.local
next step to copy all cakephp files into a subdirectory inside /home/myusername/public_html/caketest
app
cake
index.php
plugins
README
vendors
.htaccess
then I set up the site to apache (not neccessary),
<VirtualHost *:80>
DocumentRoot "/home/myusername/public_html/caketest"
ServerName caketest.local
# This should be omitted in the production environment
SetEnv APPLICATION_ENV development
<Directory "/home/myusername/public_html/caketest">
Options Indexes MultiViews FollowSymLinks
AllowOverride All
Order allow,deny
Allow from all
</Directory>
</VirtualHost>
restart apache. you also need to edit the .htaccess files and place a RewriteBase directive with hte path to the actual directory, e.g.
RewriteBase /~myusername/caketest
create a database, set the db connection in cake config files and that's all.
you can point your browser to http://caketest.local
if you do not want a test site url you can skip hosts, and apache vhost creation, but the url to use should be http:/localhost/~myusername/caketest
another important thing is to enable userdir modul in apache, and also check if using php is enabled in userdirs too.
If you're on windows, get WAMP. Install it, then download CakePHP in C:\wamp\www\. Extract CakePHP in that folder so you have a folder kind of like this: C:\wamp\www\cakephp\. Now you can access the installation by going to localhost/cakephp/.
An old article of mine but still quite relevant:
Installing CakePHP
Assuming you have a *AMP setup (Apache+MySQL+PHP), just copy the files to your htdocs folder. On Ubuntu, it's /var/www, so you would create /var/www/myApp and copy the whole Cake structure into there, ending up with something like:
/var/www/myApp/app/
/var/www/myApp/cake/
/var/www/myApp/vendors/
/var/www/myApp/index.php
/var/www/myApp/.htaccess
Then you can access your app by the url: http://localhost/myApp

Resources