NETGEAR is aware of a growing number of phone and online scams. To learn how to stay safe click here.

Forum Discussion

Vaclav's avatar
Vaclav
Aspirant
Nov 13, 2013

OS 6.1.4 apache2 mod_rewrite .htaccess problem

Hi,
I'm trying configure apache2 to enable mod_rewrite in my HTTP enabled share folder. I use that folder as my personal webserver for PHP development.

I have root access via SSH to my ReadyNAS, I know little bit of linux commands, but this I first time configure Apache, so I lack knowledge of conventions there. I followed tons of forum threads and tutorial, some of them points me to right direction, but majority of them was obsolete or too brief for me to understand.

I figured, that mod_rewrite is installed and enabled, but not working in my web share probably because Apache ignore my .htaccess file. Some folks suggests change
AllowOverride None
to
AllowOverride All


I'll sum my problems with this approach in following list.


  1. I have mess in config files. Debian uses custom modular Apache2 configuration and ReadyNAS inserts another mess in this order, because some files are reconfigured after restart. Some older tutorials points the configuration files to /etc/frontview, but I suggest, that for OS 6.1.4 the right folder is /etc/apache2 . Right?

  2. I changed AllowOverride All in
    /etc/apache2/sites_enabled/000-fv-http
    With that, my document_root containing .htaccess is forbidden, so the .htaccess starts to do something, but not the way i wanted.

  3. Some tutorials suggests add new virtual host as new file into
    /etc/apache2/sites_enabled/
    I tried it several ways, but it always brokes apache2 service, so it fails restart.

  4. I also dont understand paths in virtual hosts files. My HTTP share have name www, so system path to some project is
    /data/www/[project]/[document_root]
    but I presume, that path for virtual host would be
    /var/www/www/[project]/[document_root]
    Am I right?

  5. There is also noted importance of permissions for apache config files and for .htaccess. People say, that it should have the same user:group as apache. Apache config files has root:root, in apache2.conf the user and group are represented by envar
    $[APACHE_RUN_USER]
    $[APACHE_RUN_GROUP]
    that envars are not listed when I execute command set. There is user:group www-data:www-data in /etc/passwd, but is that even related with apache somehow?


  6. In the end, I'm realy confused from all of that. I'm sure, that I don't do everything completelly wrong, but I don't do something important here, something important there and it just don't work, but it starts doing me mad.

    Can you help with advice. Thanks in advance. I'll be also glad for good, understandable, up-to-date, article about apache basics.

5 Replies

Replies have been turned off for this discussion
  • OK, so i sorted it a little bit. Back to the points:

    1. ReadyNAS frontview, that means web administration and addons, are in
      /etc/frontview/
      Files in this folder are (or was) persistent through restart/upgrade, so it is (or was) used as hack for keep settings.
      The main apache configuration files are in
      /etc/apache2/
      and while experimenting with settings, there is no need to go to /etc/frontview.

    2. Still the same result (403 Forbidden) when edit
      /etc/apache2/sites_enabled/000-fv-http
      Changed
      <Directory />
      --Options FollowSymLinks
      ++Options All
      --AllowOverride None
      ++AllowOverride All
      </Directory>

      Incriminated .htaccess
      # Apache configuration file (see httpd.apache.org/docs/current/mod/quickreference.html)

      # disable directory listing
      Options -Indexes

      # enable cool URL
      <IfModule mod_rewrite.c>
      RewriteEngine On
      # RewriteBase /

      # prevents files starting with dot to be viewed by browser
      RewriteRule /\.|^\. - [F]

      # front controller
      RewriteCond %{REQUEST_FILENAME} !-f
      RewriteCond %{REQUEST_FILENAME} !-d
      RewriteRule !\.(pdf|js|ico|gif|jpg|png|css|rar|zip|tar\.gz)$ index.php [L]
      </IfModule>

      # enable gzip compression
      <IfModule mod_deflate.c>
      AddOutputFilterByType DEFLATE text/html text/plain text/xml text/css application/x-javascript text/javascript application/javascript application/json
      </IfModule>


    3. Tutorials related with VirtualHosts are mostly about clean domain names → redirect/translate from www.example.com to www.readynas.com/webshare/... so if I need put mod_rewrite into operation, there is no need fiddle with VirtualHosts, right?

    4. Paths in configuration files are regular system paths, I got it now :oops:

    5. Still confused here, dont know if it's even related with my problem.
  • why not creating you own conf file for your http site without touching /etc/apache2/sites_enabled/000-fv-http which could be rewritted after a fw upgrade ?
  • why not creating you own conf file for your http site without touching /etc/apache2/sites_enabled/000-fv-http which could be rewritted after a fw upgrade ?


    I created separed apache configuration file for my project
    /etc/apache2/sites-enabled/010-nette

    That file has following content
    root@nas-35-05-E7:/data/www/nette/www# cat /etc/apache2/sites-enabled/010-nette
    <Directory /data/www/nette/>
    AllowOverride All
    Options +Indexes
    Order allow,deny
    Allow from all
    </Directory>


    That file put my .htaccess into action, but it leads to 403 / forbidden. Now playing with permission.

    Files in web shared folder must be owned by webserver user. Variables
    $[APACHE_RUN_USER]
    $[APACHE_RUN_GROUP]
    are defined in /etc/apache2/envars so
    cat /etc/apache2/envars
    tells, that webserver user:group pair on OS6 is admin:admin. Can also be verified by checking running apache2 process
    ps -aux | grep apache2


    I decided to change webserver user from admin to www-data, so I changed envars from admin to www-data and restarted apache. Files and folders in web shared folder had mixed ownership and permissions, so to be sure, that ewerything is owned by the same user with propper permission, I ran
    chown -R www-data
    chmod -R 0755
    on folder /data/www/nette/, where I need mod_rewrite enable. Still getting 403 / Forbidden
  • Returning envars back to admin. Chown user back to admin:admin. The problem is probably not related with file permission. By some security reason, the rewrite engine is premitted to work only on enabled virtual hosts.

    Changed /etc/apache2/sites-enabled/010-nett to
    root@nas-35-05-E7:/# cat /etc/apache2/sites-enabled/010-nette
    <VirtualHost *:80>
    DocumentRoot /data/www/nette/www/


    <Directory /data/www/nette/www>
    Options FollowSymLinks
    RewriteEngine On
    AllowOverride All
    Order allow,deny
    Allow from all
    </Directory>

    </VirtualHost>


    Page works, no more forbidde, but RewriteEngine is off, not sure if .htaccess is doing something.
  • Finished my Apache2 excourse. PROBLEM SOLVED,
    will sumarize solution and tips for the others.

    1. Firstly, the problem was not related with file permission. Ownership was set propperly to admin:admin, which is what you need for web access as well as for local network sharing. There's no need to fiddle with permissions in most cases.
    2. You need create your configuration in
      /etc/apache2/sites-enabled
      You should create separed file for your configuration. Since all files in that folder are included by apache in order by filename, it is good convention to start your configuration file with number higher than alredy existing files. There are configuration files for frontview (ReadyNAS administration page), that begins with 000- and apps configuration files begins with 090-, I named my configuration file like 099-.
    3. You could put your config file directly in sites-enabled folder or you can put it in sites-available, which will make that site available, but not enabled yet. You can than enable that config file with command
      a2ensite <your_config_name>
      It is usefull, if you want sometimes shutdown that site with command
      a2dissite <your_config_name>
      but as far as I know, otherwise from this purpose, it doesn't matter.
    4. Because of some security reason, the rewriteEngine is only permitted to operated under configured virtual host. I firstly configured only <Directory>, which led to 403 : forbidden. In the end, I use this config

      <VirtualHost *:80>
      ServerName <your_server_name>
      DocumentRoot <your_path_to_DocumentRoot>

      <Directory <your_path_to_DocumentRoot> >
      Options FollowSymLinks
      AllowOverride FileInfo Options
      Order allow,deny
      allow from all
      </Directory>
      </VirtualHost>
      Apache documentation recommends leave all directory paths without last slash and you can ommit double quotes, but I saw config files with that in place and it seem to operate normally.

    5. In <Directory> section, I allowed to override FileInfo and Options, which is perfect minimum for RewriteEngine to work. You must also enable FollowSymLinks in options!

    6. Than you have to link <your_server_name> to your NAS, that means modify hosts file on your machine. I use Win7, so I modified
      Windows/system32/driver/etc/hosts
      added new line
      <your_NAS_IP>    <your_server_name>
      I use serverName without top level domain (country code), so it'll not conflict with some existing page.

    7. Once its all configured, you can enter <your_server_name> into address bar of your web browser and it should redirect you to your web shared folder with rewriteEngine on. Beware of your browser, sometimes it perform search your_server_name on search engine, instead of access it. It is crucial to acces your folder through <your_server_name>. I accessed them differently before and that also led to error 403 : forbidden.

    8. Dont forget to run
      service apache2 reload
      after changes to take effect.

NETGEAR Academy

Boost your skills with the Netgear Academy - Get trained, certified and stay ahead with the latest Netgear technology! 

Join Us!

ProSupport for Business

Comprehensive support plans for maximum network uptime and business peace of mind.

 

Learn More