Dec. 25, 2023
No /var/run/postgresql/.s.PGSQL after reboot (Ubuntu)
Rebooting the server, bumped into the following error, preventing my django server from functioning: psql: error: connection to server on socket "/var/run/postgresql/.s.PGSQL.xxxx" failed: No such file or directoryNot to easy to search the solution, tons of search spam (and of course stupid advises "purge porstgresql including databases and all the files and reinstall".
Thanks to Abdallah: https://www.abdallahyashir.com/how-to-fix-postgresql-error-connection-to-server-on-socket-failed/
$ sudo -i -u postgres
$ /usr/lib/postgresql/14/bin/pg_ctl restart -D /var/lib/postgresql/14/main
#linux #postgresql #django
Dec. 8, 2023
django app: Resource blocked due to MIME type mismatch
#boring #django #nginxRunning your Django app first time in production, you might bump into the issue of your browser blocking static resources (.css, .js) with a message "Resource blocked due to MIME type mismatch". I was googling a bit here and there, most results are providing a bit context demanding answers.
The X-Content-Type-Options response HTTP header is a marker used by the server to indicate that the MIME types advertised in the Content-Type headers should be followed and not be changed.
(The document provided by the link "explaining" the issue in the browser)
Dude, what do I do? Some answers on Stack Overflow recommend to turn of security features in your browser. Well, swiping the issue under the carpet does not make it go.
Long story short, running Django in production, you just have to properly set up your Nginx.
The instruction presumes you have everything going fine with DEBUG = True in your Django settings.
If you have your project static files in the folder /var/www/mysite/myapp/myapp/static, add the following location block to your server in nginx configuration:
location /static/ {
alias /var/www/mysite/myapp/myapp/static/;
}
You would need to add this kind of block for every application in your project, having its own static files.
Restart your nginx, and that should be it.
--
To run your project locally with debug mode off, but keep static files unblocked by MIME type, launch it as usually, but add "--insecure" flag:
./manage.py runserver --insecure
1