I just upload a website Django application on AWS using NGINX and uwsgi protocol. The website is running fine but only part of the minified version of CSS is loaded. More specificaly the part of the css which configures the footer section of the page doesn't load. But all the CSS is in the same file.
NGINX conf file is something like this:
`upstream django {
server unix:///home/ubuntu/django-apache-nginx-uwsgi-vps-ubuntu /mysite.sock;
}
server {
listen 8000;
server_name example.com;
charset utf-8;
client_max_body_size 75M;
location /media {
alias /home/ubuntu/django-apache-nginx-uwsgi-vps-ubuntu/media;
}
location /static {
alias /home/ubuntu/django-apache-nginx-uwsgi-vps-ubuntu/static;
}
location / {
uwsgi_pass django;
include /home/ubuntu/django-apache-nginx-uwsgi-vps-ubuntu/uwsgi_params;
}
}
`
Related
I'm trying to set up a Django website with uwsgi and nginx. I created configuration file mysite.conf:
# the upstream component nginx needs to connect to
upstream django {
server unix:///home/path/to/mysite/mysite.sock;
}
# configuration of the server
server {
listen 80;
server_name mydomain.com www.mydomain.com;
charset utf-8;
# max upload size
client_max_body_size 350M;
# Django media and static files
location /media {
alias /home/path/to/mysite/media;
}
location /static {
alias /home/path/to/mysite/static;
}
# Send all non-media requests to the Django server.
location / {
uwsgi_pass django;
include /home/path/to/mysite/uwsgi_params;
}
}
And it gives this error:
nginx: [emerg] "upstream" directive is not allowed here in /etc/nginx/sites-enabled/mysite.conf:2
I don't why it happens. I followed this tutorial: https://tonyteaches.tech/django-nginx-uwsgi-tutorial/
The problem was that i included configuration files before http tag.
It should be:
http {
include /etc/nginx/sites-enabled/*;
...
}
This can also happen if your file is being deployed over the directory /etc/nginx/conf.d/ but the default config is including files from http.d instead:
include /etc/nginx/http.d/*.conf;
so try also to deploy it over /etc/nginx/http.d/
I have a problem with nginx and django.
Config:
server {
listen 80;
server_name 193.88.95.120;
charset utf-8;
root /root/djangoprojects/megaproject;
client_max_body_size 75M;
location /media {
alias /root/djangoprojects/media/;
}
location /static {
alias /root/djangoprojects/megapproject/megaapp/static/;
}
location / {
include /root/djangoprojects/megaproject/uwsgi_params;
}
}
Error 403 - forbidden.
When I create an index file in the project folder .html " - it opens.
But I need Django to work.
Please help me.
All configurations are being included and conf test is passed too. But Nginx is still serving the default HTML from /usr/share/nginx/html, instead of location root from conf file in conf.d directory.
conf file from conf.d directory
upstream django {
server unix:///tmp/server.sock;
}
server {
listen 80;
server_name server.test.com;
access_log /srv/source/logs/access-nginx.log;
error_log /srv/source/logs/error-nginx.log;
location / {
uwsgi_pass django;
include /srv/source/conf/uwsgi/params;
}
location /static/ {
root /srv/source/;
index index.html index.htm;
}
location /media/ {
root /srv/source/media/;
index index.html index.htm;
}
# alias favicon.* to static
location ~ ^/favicon.(\w*)$ {
alias /srv/source/static/favicon.$1;
}
}
The default nginx config is in /etc/nginx/nginx.conf. By default that file includes the following lines (at least that is the case on rhel based and arch based distros):
include /etc/nginx/conf.d/*.conf;
server {
listen 80 default_server;
listen [::]:80 default_server;
server_name _;
root /usr/share/nginx/html;
# Load configuration files for the default server block.
include /etc/nginx/default.d/*.conf;
location / {
}
error_page 404 /404.html;
location = /40x.html {
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
}
}
Thanks to the root in the server section nginx will keep serving the files under that directory until you comment our these lines. This happens just after conf.d is loaded (as noted in the snippet above).
No matter what you change inside conf.d that last part of the file will still be loaded. Since it is that file (/etc/nginx/nginx.conf) that loads the configs in conf.d.
And yes, you definitely should comment out that default server if you plan to use nginx.
I am encountering an issue with my nginx django setting.
Well, when I load the project using their development server everything is ok.
When I load it from nginx, it looks it's not really loading good project.
I made a test, I edited the settings.py file leaving a syntax error and well it didn't load on the internal server of django, but, it loaded with nginx. So I guess nginx isn't linked to the right config but I can't get why as I only created one project.
Config file is the following (nginx):
server {
listen 80;
server_name sub.example.com;
access_log /var/www/sub.example.com/log/access.log;
error_log /var/www/sub.example.com/log/error.log;
## Default location
location / {
include fastcgi_params;
fastcgi_pass 127.0.0.1:8888;
fastcgi_split_path_info ^()(.*)$;
}
location /static/ { # STATIC_URL
alias /var/www/sub.example.com/static/; # STATIC_ROOT
expires 30d;
}
location /media/ { # MEDIA_URL
alias /var/www/sub.example.com/media/; # MEDIA_ROOT
expires 30d;
}
}
I'm building a website using Django + Apache and Nginx to serve my static content. My site's index does not require any backend Django coding, so what would I need to change in nginx.conf to send requests for location / { } to some index.html in my static-content, while still allowing my urls.py to handle patterns appropriately?
upstream backend {
server 127.0.0.1:8080;
}
server {
listen 192.168.1.20:80;
server_name www.example.com example.com;
access_log /home/userxyz/public_html/example.com/logs/nginx_access.log;
error_log /home/userxyz/public_html/example.com/logs/nginx_error.log;
location /
{
proxy_pass http://127.0.0.1:8080;
include /etc/nginx/proxy.conf;
}
location ~ ^/(system|images|robots\.txt|css|js|favicon\.ico).*$
{
root /home/userxyz/public_html/example.com/static-content/;
}
location /media/
{
root /home/userxyz/public_html/example.com/;
}
}
location = / {
root /home/userxyz/public_html/example.com/static-content/;
}
What about something like:
location ~ ^/$
{
root /PATH/TO/index.html;
}
The idea is to give nginx a rule for exactly matching '/'.