Nginx routing Django Web App links to wrong path - django

I have a django app where the hompage routes correctly, but when I try to click on any of the links I get a 404 error. I looked at the logs and see:
*1 open() "/usr/share/nginx/html/pricing" failed (2: No such file or directory)
which tells me that nginx is not looking at my project folder but instead what seems to be a default setting. I am using centos, so I had to manually setup sites-available and sites-enabled, which I have used to get the homepage working. As such there is no default conf to disable. I am unsure how to get nginx to route to my path instead of the default. My nginx.conf file looks like this:
user so_dev;
worker_processes auto;
error_log /var/log/nginx/error.log;
pid /run/nginx.pid;
include /usr/share/nginx/modules/*.conf;
events {
worker_connections 1024;
}
http {
log_format main '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"';
access_log /var/log/nginx/access.log main;
sendfile on;
tcp_nopush on;
tcp_nodelay on;
keepalive_timeout 65;
types_hash_max_size 2048;
include /etc/nginx/mime.types;
default_type application/octet-stream;
include /etc/nginx/conf.d/*.conf;
include /etc/nginx/sites-enabled/*; #added by me
}

I followed a bad tutorial which had a typo in it. If you happen to follow same type, inside your nginx sites-available file you should put:
location /
and NOT
location = /
https://www.shellvoide.com/hacks/installing-django-application-with-nginx-mysql-and-gunicorn-on-ubuntu-vps/

Related

Nginx Gives 502 Error but config should be correct; Please I need advise on how to debug the issue?

I have a CentOS 8 (fedora) server running and I'm trying to run my Django Webapp on it through Nginx
It runs on port 8000, and I want to access it on my browser through nginx (so port 80?)
These commands on the server itself
This shows my webapp HTML page fine
curl http://127.0.0.1:8000
curl http://0.0.0.0:8000
but these show me the Nginx 502 Bad Gateway page
curl http://0.0.0.0
curl http://127.0.0.1
No errors in the nginx log files
This is my nginx.config:
events {
worker_connections 1024;
}
http {
log_format main '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"';
access_log /var/log/nginx/access.log main;
error_log /var/log/nginx/error.log;
sendfile on;
tcp_nopush on;
tcp_nodelay on;
keepalive_timeout 65;
types_hash_max_size 2048;
include /etc/nginx/mime.types;
default_type application/octet-stream;
server_tokens off;
server {
listen 80;
server_name $hostname; # I tried this with an '_' also no help
location / {
proxy_pass http://0.0.0.0:8000; # also tried with 127.0.0.1
proxy_set_header Host $host;
}
}
}
Running
nginx -T shows the config has been loaded
Any advise on what to look for? (perhaps my firewall is blocking it somehow? idk)
Kind regards
I'm trying to get my webpage working through Nginx
Looks like it was a firewall issue, I needed to open the port to accept messages
iptables -I INPUT 1 -i eth0 -p tcp --dport 8000 -j ACCEPT

nginx: [emerg] invalid number of arguments in "include" directive

I am learning how to deploy AWS for the first time. I am following this guide here: https://www.youtube.com/watch?v=HtWgb_vbyvY.
I am using windows machine while the person in the video uses mac.
I am getting the following error when running ngnix commands on the windows terminal: "nginx: [emerg] CreateFile() "C:/nginx-1.23.0/nginx-1.23.0/mime.types" failed (3: The system cannot find the path specified) in C:\Users\Shi Jie\Downloads\nginx-1.23.0\nginx-1.23.0/conf/nginx.conf:12"
i think it is how i write the path on my ngnix.conf which i write as such
worker_processes 1;
error_log /var/log/nginx/error.log warn;
pid /var/run/nginx.pid;
events {
worker_connections 1024;
}
http {
include \Users\Shi Jie\Downloads\nginx-1.23.0\nginx-1.23.0\mime.types;
default_type application/octet-stream;
log_format main '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"';
access_log /var/log/nginx/access.log main;
sendfile on;
#tcp_nopush on;
client_body_buffer_size 100k;
client_header_buffer_size 1k;
client_max_body_size 100k;
large_client_header_buffers 2 1k;
client_body_timeout 10;
client_header_timeout 10;
keepalive_timeout 5 5;
send_timeout 10;
server_tokens off;
#gzip on; on;
include /etc/nginx/conf.d/*.conf;
}
Can anyone point the way to teach me how to write the path properly? Thank you.
You need to escape spaces, { and ". So change your include line to the following:
...
include /Users/Shi\ Jie/Downloads/nginx-1.23.0/nginx-1.23.0/mime.types;
...

NGINX Logging on AWS with ec2-user is not happening

Below is my edited nginx.conf
user ec2-user;
worker_processes auto;
error_log /var/log/nginx/error.log;
pid /run/nginx.pid;
include /usr/share/nginx/modules/*.conf;
events {
worker_connections 2048;
}
http {
log_format main '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"';
access_log /var/log/nginx/access.log main;
sendfile on;
#tcp_nopush on;
#tcp_nodelay on;
keepalive_timeout 65;
include /etc/nginx/mime.types;
default_type application/octet-stream;
include /etc/nginx/conf.d/*.conf;
}
When I changed the user variable from nginx user to ec2-user, the logs are not getting captured in the /var/log/nginx/access.log file even though the file is present it always remains zero size

NGINX gives 502 error from browsers but not from Postman

I've got a Django application running on Azure App Service using NGINX.
My nginx.conf file is as follow:
user nginx;
worker_processes 1;
error_log /var/log/nginx/error.log warn;
pid /var/run/nginx.pid;
events {
worker_connections 1024;
}
http {
include /etc/nginx/mime.types;
default_type application/octet-stream;
log_format main '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"';
access_log /var/log/nginx/access.log main;
sendfile on;
keepalive_timeout 65;
fastcgi_max_temp_file_size 0;
fastcgi_buffers 128 2048k;
fastcgi_buffer_size 2048k;
proxy_buffer_size 128k;
proxy_buffers 4 256k;
proxy_busy_buffers_size 256k;
server {
listen 8000;
location / {
include uwsgi_params;
uwsgi_pass unix:///tmp/uwsgi.sock;
}
location /static {
alias /app/staticfiles;
}
}
}
daemon off;
Everything works fine, except for one particular API where I include in the header some token (typical bearer token) and it's returning a 502 error from Chrome (in the network tab)
However, when I try to call this from Postman, it's returning the data correctly.
What could be possibly wrong here?
Thanks to #Selcuk's suggestion. I've managed to fix the above error by increasing the buffer-size in iwsgi.ini file
# uwsgi.ini file
buffer-size = 32768

Setup pretty local development URLs with nginx on Mac OS X

I have a Django server setup that I can access from 127.0.0.1:8000
I have just installed nginx on to Mac OS X Yosemite and can access the 'Welcome to nginx' screen at localhost:80
I want to be able to set up a local development environment on local.ingledow.co.uk but when I visit that URL, it redirects me to my live site: david.ingledow.co.uk.
I did have a wildcard URL forwarder with DNSimple that would redirect like this:
*.ingledow.co.uk > david.ingledow.co.uk
but I have removed that.
I have added this CNAME: local.ingledow.co.uk > 127.0.0.1
This shouldn't affect how I setup my local nginx servers.
So, how do I create an nginx server on Mac that shows my 127.0.0.1:8000 Django project on to a custom domain (local.ingledow.co.uk).
This is my nginx setup:
Default Nginx config at /usr/local/etc/nginx/nginx.conf
#user nobody;
worker_processes 1;
#error_log logs/error.log;
#error_log logs/error.log notice;
#error_log logs/error.log info;
#pid logs/nginx.pid;
events {
worker_connections 1024;
}
http {
include mime.types;
default_type application/octet-stream;
#log_format main '$remote_addr - $remote_user [$time_local] "$request" '
# '$status $body_bytes_sent "$http_referer" '
# '"$http_user_agent" "$http_x_forwarded_for"';
#access_log logs/access.log main;
sendfile on;
#tcp_nopush on;
#keepalive_timeout 0;
keepalive_timeout 65;
#gzip on;
server {
listen 80;
server_name localhost;
#charset koi8-r;
#access_log logs/host.access.log main;
location / {
root html;
index index.html index.htm;
}
#error_page 404 /404.html;
# redirect server error pages to the static page /50x.html
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
}
# INCLUDES
include /Users/dingledow/etc/nginx/*.conf;
}
ingledow.conf at /Users/dingledow/etc/nginx/ingledow.conf
server {
listen 80;
server_name local.ingledow.co.uk;
location / {
root /Users/dingledow/Documents/Work/Ingledow/git/my_site2/;
index index.html index.htm index.php;
autoindex on;
}
}
I'm not sure if Apache is conflicting with nginx? Or whether I've just setup nginx incorrectly?
Setting a CNAME with your registrar isn't going to help at all, and you should remove that.
The only way to make this work is to edit your local HOSTS file at /etc/hosts and add a pointer to the localhost:
127.0.0.1. local.ingledow.co.uk
Then you'll either need to run the dev server on port 80 instead of 8000, or configure nginx to run your site via gunicorn or uwsgi - the documentation tells to how to do that.