samedi 24 février 2018

Why doesn't appache allow access to files outside the web root --from within index.html?

As the title states..

I have the following organization to my project but am unable to access the related css and javascript files from within my html code --unless I create symbolic links from the file to my web root. Is this normal behavior for apache or does the problem lie elsewhere?

If I remove the symbolic links and correct the path in my src attributes the content of those outside files becomes inaccessible

userName@hostName:/var/www/test$ tree
.
├── css
│   └── style.css
├── html
│   ├── code.js -> ../js/code.js
│   ├── index.html
│   ├── jquery-3.2.1.js -> ../libs/jquery-3.2.1.js
│   └── style.css -> ../css/style.css
├── js
│   └── code.js
└── libs
    └── jquery-3.2.1.js

4 directories, 7 files

userName@hostName:/var/www/test$ less html/index.html

<!doctype HTML>
<html>
   <head>
      <meta charset="utf-8">
      <meta name="viewport" content="width=device-width, initial-scale=1.0">
      <link rel="stylesheet" type="text/css" href="./style.css">
      <title>Test</title>
   </head><!-- head -->
   <body>
     <h1>LOCAL TESTING SITE..</h1>
   </body><!-- body -->
    <script src="./code.js"></script>
</html><!-- html -->

html/index.html (END)

^ Works

userName@hostName:/var/www/test$ tree
.
├── css
│   └── style.css
├── html
│   ├── index.html
├── js
│   └── code.js
└── libs
    └── jquery-3.2.1.js

4 directories, 7 files

userName@hostName:/var/www/test$ less html/index.html

<!doctype HTML>
<html>
   <head>
      <meta charset="utf-8">
      <meta name="viewport" content="width=device-width, initial-scale=1.0">
      <link rel="stylesheet" type="text/css" href="../css/style.css">
      <title>Test</title>
   </head><!-- head -->
   <body>
     <h1>LOCAL TESTING SITE..</h1>
   </body><!-- body -->
    <script src="../js/code.js"></script>
</html><!-- html -->

html/index.html (END)

^ Does NOT Work

userName@hostName:/var/www/test$ tree -p
.
├── [drwxrwxr-x]  css
│   └── [-rw-rw-r--]  style.css
├── [drwxrwxr-x]  html
│   ├── [lrwxrwxrwx]  code.js -> ../js/code.js
│   ├── [-rw-rw-r--]  index.html
│   ├── [lrwxrwxrwx]  jquery-3.2.1.js -> ../libs/jquery-3.2.1.js
│   └── [lrwxrwxrwx]  style.css -> ../css/style.css
├── [drwxrwxr-x]  js
│   └── [-rw-rw-r--]  code.js
└── [drwxrwxr-x]  libs
    └── [-rw-rw-r--]  jquery-3.2.1.js

4 directories, 7 files

^ Permissions on files

userName@hostName:/etc/apache2$ less sites-available/test.local.conf

<VirtualHost *:80>
        ServerAdmin myEmail@email.com
        DocumentRoot /var/www/test/html
        ServerName test.local
        ErrorLog ${APACHE_LOG_DIR}/test.local.error.log
        CustomLog ${APACHE_LOG_DIR}/test.local.access.log combined
</VirtualHost>

# vim: syntax=apache ts=4 sw=4 sts=4 sr noet

sites-available/test.local.conf (END)

^ Virtual Host Configuration

userName@hostName:/var/www/test$ uname -v

#35~16.04.1-Ubuntu


userName@hostName:/var/www/test$ apache2 -v

Server version: Apache/2.4.18 (Ubuntu)

^ System Info




Aucun commentaire:

Enregistrer un commentaire