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.
Related
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;
}
}
`
My issue is that whenever I try to view a webpage that isn't the root webpage aka /user/ nginx returns a 404 error and the error log states
"/usr/share/nginx/html/user/login/index.html" is not found.
current nginx configuration
server {
listen 80;
server_name ip_address;
location = /static {
root /opt/scrumban/kanbanboard/;
autoindex off;
}
location = / {
include proxy_params;
proxy_pass http://unix:/opt/scrumban/kanbanboard/kanban.sock;
}
}
Remove those = signs; they mean that only the paths "/" and "/static" are matched. Without the symbol they match as prefixes, which is what you want.
I have a centOS with a virtualenv, i can use the project in my localhost , but when the project is upload to a server give an error :
502 - bad gateway
I think the problem probably is in my nginx file.
server {
listen 80;
server_name www.site.com.br site.com.br;
root /var/www/html/agrodez/src/;
if ($http_host != "www.site.com.br") {
rewrite ^ http://site.com.br$request_uri permanent;
}
location /static/ {
alias /var/www/html/site/src/sistema/static/;
}
location /{
proxy_pass http://localhost:8000;
include /etc/nginx/proxy_params;
}
I don't know much about django, but recently I had to help a team with server configuration, and I've used the following nginx virtualhost configuration:
upstream django.local {
server 127.0.0.1:8000;
}
server {
listen 80;
server_name site.com;
location / {
root html;
index index.html index.htm;
proxy_pass http://django.local/;
}
location /static {
autoindex on;
# this line would be STATIC_ROOT dir
alias /var/www/html/agrodez/src/staticfiles;
}
location /media {
autoindex on;
# this line would be MEDIA_ROOT dir;
alias /var/www/html/agrodez/src/media;
}
# If you want nginx logs, then can add these
error_log /var/log/nginx/site.com_error.log;
access_log /var/log/nginx/site.com_access.log;
}
You can give it a try.
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'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 '/'.