Apache2: Disable directory listing globally - list

I've a Debian WebServer running Apache2.
How can I disable directory listing, globally, for all websites?
Note: This should also overwrite possible settings of virtual hosts.

Issue the following in you server terminal:
sudo a2dismod autoindex
service apache2 reload
After this all websites will have directory listing disabled.

Related

How to run django app on windows server ec2 instance with mysql database and costum domain

I have Copied my files to the server and also setup the domain in the route 53 and also installed the xampp server now
When i try starting the server with the command Python manage.py runserver 0.0.0.0:80
it gives me the following error
Error: [WinError 10013] An attempt was made to access a socket in a way forbidden by its access permissions
but when i visit the domain it autmatically redirected to
domian.com/dashboard/
and there is all the xampp and apache etc stuff
i tried to run it with out specifying the ip and port the it redirects to the domian/dashboard
i want this to use the xampp server for mysql and run on the domain
it seems you're using the the in-built Django webserver that is meant for development purposes but not the best for production follow the steps below Deploy Django Applications on windows server using XAMPP
Prerequisite: make sure that your project already have a virtual environment, and you copied your project folder into C:\xampp\htdocs.
also you might need windows 10 sdk installed.
Step 1:
first we should set mod wsgi apache rootdir to our xampp apache directory , so in you cmd type:
set “MOD_WSGI_APACHE_ROOTDIR=c:\xampp\apache”
Step 2:
activate your project environment
Step 3:
In your virtual environment type:
pip install mod_wsgi
Step 4:
then type this:
mod_wsgi-express module-config
the output result should be something like this:
LoadFile “c:/python37–32/python37.dll” LoadModule wsgi_module
“c:/python37–32/lib/site-packages/mod_wsgi/server/mod_wsgi.cp37-win32.pyd”
WSGIPythonHome “c:/python37–32”
Step 5:
open http.conf file and copy to LoadFile and LoadModule from previous step on it
Step 6:
copy this lines in http.conf too:
#path to wsgi.py file #the first “/ “ indicates the root url
WSGIScriptAlias /
“C:/xampp/htdocs/your_project_folder/your_project/wsgi.py”
#the one that you get from step 4
WSGIPythonHome “c:/python37–32”
#website path
WSGIPythonPath “C:/xampp/htdocs/your_project_folder”
#directory of website
<Directory “C:/xampp/htdocs/your_project_folder/your_project”>
Require all granted
Step 7:
Restart your xampp and enjoy
You may also find more details on this post

Debuggin django log on NGINX - DigitalOcean

I have a Django application (droplet) on DigitalOcean but I have an issue showing information in a table.
Everything works on my local server but when I deploy to the server on DigitalOcean I don't know where I can see the activity of the server like print outputs. I can see the gunicorn and nginx logs but none of those logs show the Django activity.
What should I do?
Create your Log directory
mkdir logs in your-app directory
To get your django requests and error log; you'd have to create your indicate the log directory in your nginx server config file.
/etc/nginx/sites-available/your-app-config:
server {
...
access_log /directory/to/your-app/logs/access.log;
error_log /directory/to/your-app/logs/error.log;
...
}
Ensure you have a symbolic link to the sites-enabled folder:
sudo ln -s /etc/nginx/sites-available/your-app /etc/nginx/sites-enabled/your-app
Check that your configuration settings are okay
sudo nginx -t
Reload Nginx
sudo systemctl reload nginx
Check your log files to read requests & error logs

500 internal server error when changing the db from sqlite to postgres with django and nginx

I am wondering about some things, i followed this tutorials setting up server
I am currently using django 2.2, psycopg2 2.8.3, uwsgi 2.0.18.
I am able to migrate models to db but the nginx server failed to communicate with it.
I added local host with port 5432 to cors header.
does this a permission issue, as nginx runs with a user? or it is something else? should i use https for local host in cors header allowed hosts as nginx and django only allow https requests?
the problem was psycopg2 wasn't installed in venv location, even when i activate venv it does't install it in the venv dir. so i copy it from the location where it was installed to venv lib/site-packages, and it worked perfectly.

nginx Permission denied on Ubuntu

I'm trying to set up my Django app with uWSGI and nginx by following this guide. I'm able to run my app with Django's development server, as well as being served directly from uWSGI.
I'm running everything on a university managed Ubuntu 16.04 virtual machine, and my user has sudo access.
My problem:
When getting to this bit of the tutorial, and try to fetch an image, I get a 403 error from nginx.
The next section results in a 502.
/var/log/nginx/error.log shows
connect() to unix:///me/myproject/media/image.jpg failed (13: Permission denied) while connecting to upstream
connect() to unix:///me/myproject/project.sock failed (13: Permission denied) while connecting to upstream
for the 403 and 502, respectively.
I have read multiple questions and guides (one here, another here and yet another one, and this is not all of them), changed my permissions and even moved my .sock to another folder (one of the SO answers recommended that).
What else can I try?
Update:
I mentioned it in a comment, but I've gotten a bit further. A part of the problem was that, apparently, the /home directory on my VM is NFS, which messes up a good many permissions.
What I've done:
I've set up my project in /var/www/myproject/
Run chown -R me:www-data myproject
Run chmod -R 764 myproject
My new results:
Without nginx running:
uwsgi --http :8000 --module myproject.wsgi
works perfectly
With nginx running:
uwsgi --socket myproject.sock --module myproject.wsgi --chmod-socket=664
gives me a 502
uwsgi --ini myproject.ini
gives me a 502
So now it's not a general permission issue, it's definitely an issue with nginx...
Update #2:
For the moment, everything is working when other has read-write permissions on the socket, and read-execute permissions on the rest of the project.
So nginx is not recognized as it should... I've double-checked, and nginx is running as the www-data user, which is the group-owner of my entire project, and which has read-execute permissions, just as other now has.
Here's my (updated) nginx.conf
# myproject_nginx.conf
# the upstream component nginx needs to connect to
upstream django {
# server unix:///path/to/your/mysite/mysite.sock; # for a file socket
server unix:///var/www/myproject/myproject.sock;
# server 127.0.0.1:8001; # for a web port socket (we'll use this first)
}
# configuration of the server
server {
# the port your site will be served on
listen 8000;
# the domain name it will serve for
server_name my.ip.goes.here; # substitute your machine's IP address or FQDN
charset utf-8;
# max upload size
client_max_body_size 75M; # adjust to taste
# Django media
location /media {
alias /var/www/myproject/media; # your Django project's media files - amend as required
}
location /static {
alias /var/www/myproject/static; # your Django project's static files - amend as required
# Finally, send all non-media requests to the Django server.
location / {
uwsgi_pass django;
include /var/www/myproject/uwsgi_params; # the uwsgi_params file you installed
}
}
And here's my (updated) uwsgi.ini
# myproject_uwsgi.ini file
[uwsgi]
# Django-related settings
# the base directory (full path)
chdir = /var/www/myproject
# Django's wsgi file
module = myproject.wsgi
# the virtualenv (full path)
home = /var/www/myenv
# process-related settings
master = true
# maximum number of worker processes
processes = 10
# the socket (full path)
socket = /var/www/myproject/myproject.sock
# ... with appropriate permissions - may be needed
chmod-socket = 666
uid = me
gid = www-data
# clear environment on exit
vacuum = true
From my experience, most of the permission problems around web server are by accessing file which is owned by root, but Apache (nginx) is running under www-data user.
Try running sudo chown www-data -R /path/to/your/data/folder.
As the tutorial said:
You may also have to add your user to nginx’s group (which is probably
www-data), or vice-versa, so that nginx can read and write to your
socket properly.
Try that and see what happens.
As well I wouldn't recommend you doing things with sudo or as root, do it as a normal user and place the permission as it get necessary, otherwise you might end up in a situation that Nginx or uWSGI need to do something with the files and they are owned by root.

Rooting log files with daemon mode

I'm using mod_wsgi (v.4.5.20), installed with pip, in daemon mode, using a "main" apache instance as front (reverse proxy). I'm serving a django application, the "main" server hosts some other applications.
I'ld like to record the log files to a "known" directory. For now, the log files are recorded into the directory generated by the daemon-mode, aka. --server-root directory. The process is launched through a systemd service.
On the "main" apache settings, I've set the ErrorLog and CustomLog directives to my "wanted" log directory, but no files are recorded.
The "main" apache settings: (Note the X-Forwarded-For switch for company reverse proxy)
https://gist.github.com/frague59/0c9717bd5668140de392019874373f0a
Thanks for your help !
When you use mod_wsgi-express behind a front end Apache serving as proxy, the mod_wsgi-express configuration is completely independent to the front end. If you want to change where logs go for mod_wsgi-express use the --log-directory option. Presuming mod_wsgi-express is started as not root user, it will not be able to write to a root owned directory. If it needed to, you would need to start it as root and define --user and --group options to then be what user and group you want the WSGI application to run as. Because it start as root initially, then it can write logs to a root owned directory. Run mod_wsgi-express with the --help option to see all the command line options.