I'm new to programming, I don't know where consider as "document root of web server"

20 views
Skip to first unread message

Mie Rex

unread,
Apr 27, 2016, 9:28:28 PM4/27/16
to Django users
Hello everyone, I am new to Django and quite new to Python as well.

I came across this advice while I'm going through the Django tutorial here

It mentioned "It’s not a good idea to put any of this Python code within your Web server’s document root..."
My very newbie question is:  what's document root of web server?
I have no knowledge in building a web site so please forgive my very shallow question.
Cheers
001.jpg

Lachlan Musicman

unread,
Apr 27, 2016, 9:57:26 PM4/27/16
to django...@googlegroups.com
Mie,

Traditionally the document root to your webserver is (depending on your system) /var/www.

This will be defined in the webserver (apache2/httpd, nginx, etc) configuration.

I normally create a folder in my home dir called www and place my sites within that

/home/lachlan/www/site1
/home/lachlan/www/site2

At a later point, you will need to set up your webserver to read from that directory.



Cheers
L.

------
The most dangerous phrase in the language is, "We've always done it this way."

- Grace Hopper

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users...@googlegroups.com.
To post to this group, send email to django...@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/0d8833ce-1623-4811-836a-d82a1cc39ee9%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Lachlan Musicman

unread,
Apr 27, 2016, 9:59:06 PM4/27/16
to django...@googlegroups.com
Sorry, that was a "where is" not a "what is"

The document root of your webserver is the *default* location on the file system that the webserver will look for content/websites/things to "serve".


cheers
L.

------
The most dangerous phrase in the language is, "We've always done it this way."

- Grace Hopper

Mie Rex

unread,
Apr 28, 2016, 12:41:51 AM4/28/16
to Django users
for your case, site1 and site2 are two isolate webserver, correct?
Will all the files under both of these directories open to public once the server is up and running?
Is the article from the tutorial suggest to have .py files store in some other place to avoid it being see by visitors online?
So the framework could just import scripts from designated place through PYTHONPATH even when the scripts are not placed within site1 or site2?

Thank you for such a quick response especially to my extremely novice question.
I hope I would learn a lot from this community, thank you very much

Lachlan Musicman於 2016年4月27日星期三 UTC-7下午6時57分26秒寫道:

Lachlan Musicman

unread,
Apr 28, 2016, 1:07:31 AM4/28/16
to django...@googlegroups.com
On 28 April 2016 at 14:41, Mie Rex <rexm...@gmail.com> wrote:
for your case, site1 and site2 are two isolate webserver, correct?
Will all the files under both of these directories open to public once the server is up and running?

Oops - almost, but not quite. Site1 and Site2 are two different websites, being served by the same webserver. A web server can serve as many sites as you want, so long as you configure them all correctly.

"open to the public" is a tricky phrase. In a traditional site (I'm an old man) that would have been the case - long list of .html files and they would be "served". These days it's more common for the files to be mini database-referencing programs (like .php files), or in the case of Django to be a systemic framework that requires one more server (a 'gateway interface', like Gunicorn, wsgi, fastcgi, etc - these normally execute the .py files).

That is a very complex answer - I'm sorry, but web serving is fiddly :/

But the simple answer is yes - if you have configured the server correctly, both directories will be "served".

 
Is the article from the tutorial suggest to have .py files store in some other place to avoid it being see by visitors online?
So the framework could just import scripts from designated place through PYTHONPATH even when the scripts are not placed within site1 or site2?


I can't speak to the exact reason why it is recommended that you avoid putting them in the traditional document root. I would suggest that it's almost certainly due to security reasons. I wont guess what they are, because I can think of half a dozen off the top of my head that are confusing and potentially wrong. But it's almost certainly for server security, yes.



Thank you for such a quick response especially to my extremely novice question.
I hope I would learn a lot from this community, thank you very much


No problems. I learnt a lot here too.

cheers
L.
Reply all
Reply to author
Forward
0 new messages