"proxy_pass" directive is duplicate - django

Getting the error:
nginx: [emerg] "proxy_pass" directive is duplicate in /etc/nginx/sites-enabled/mhprints:12
nginx: configuration file /etc/nginx/nginx.conf test failed
when trying to run my django project on nginx and gunicorn.
my settings in folder error points to:
server {
listen 80;
server_name 194.146.49.249;
location = /favicon.ico { access_log off; log_not_found off; }
location /static/ {
root /home/dave/mhprints;
}
location / {
include proxy_params;
proxy_pass http://unix:/run/gunicorn.sock;
}
}
Can't find a fix, hoping somebody knows on here.

Solved, used the following command:
sudo grep -ri 'proxy_pass' /etc/nginx/
Found the duplicate and deleted it.

Related

Getting 504 Gateway Time-out nginx/1.18.0 (Ubuntu) in django nginx

I am facing problems launching my django app in digitalocean. I have done all the needful but I am quite sure I made error some where. Below is my nginx configuration file. What could be the problem . Thanks alot .
PLease I would also love to know how to access nginx error log file through command line.
server {
server_name server_Ip;
location = /favicon.ico { access_log off; log_not_found off; }
location /static/ {
root /home/username/myproject/smsdigo;
}
location /media/ {
root /home/username/myproject/smsdigo;
}
location /locale/ {
root /home/ebong/myproject/smsdigo;
}
location / {
include proxy_params;
proxy_pass http://unix:/run/gunicorn.sock;
}
}
server {
listen 80;
client_max_body_size 3000M;
client_body_buffer_size 3000M;
client_body_timeout 120;
}
Problably you need increase fastcgi timeout directives:
Try 60s or more. For example:
server{
fastcgi_read_timeout 60s;
fastcgi_send_timeout 60s;
}

Nginx location doesnt workd

I have a Django app running with Nginx and Gunicorn on mysite.com. I would like it to be accessible only under mysite.com/myapp. This is my nginx configuration:
server {
listen 80;
server_name server_domain_or_IP;
location = /favicon.ico { access_log off; log_not_found off; }
location /static/ {
root /home/sammy/myprojectdir;
}
location / {
include proxy_params;
proxy_pass http://unix:/run/gunicorn.sock;
}
}
When I change location / to location /myapp/, I get "Not found error". Nginx error log doesn't seems to have anything. What could be the issue?

How to make Nginx config file for Django Project?

I made Nginx config for My Django project.
For DNS I associate with my IP.
But this config not working, when I'm checking xyz.com in web but getting error ERR_CONNECTION_REFUSED.
server {
listen 80;
server_name xyz.com;
location = /favicon.ico { access_log off; log_not_found off; }
location /static/ {
root /home/ubuntu/project;
}
location / {
include proxy_params;
proxy_pass http://unix:/home/ubuntu/project/project.sock;
}
}
Please correct me if i'm doing wrong.

How to update css/scss files with NGINX

I am running a Digital Ocean droplet with Gunicorn and NGINX. I am able
to view my web pages but I am not able to update html/css/scss.
I have added include /etc/nginx/mime.types; in /etc/nginx/nginx.conf as suggested in another post. Also tried
python manage.py collectstatic and received the following: 0 static files copied to '/home/ubuntuadmin/pyapps/nomad/static', 177 unmodified
sudo nano /etc/nginx/sites-available/nomad >>>
server {
listen 80;
server_name 157.245.0.153;
location = /favicon.ico { access_log off; log_not_found off; }
location /static/ {
root /home/ubuntuadmin/pyapps/nomad;
}
location /media/ {
root /home/ubuntuadmin/pyapps/nomad/;
}
location / {
include proxy_params;
proxy_pass http://unix:/run/gunicorn.sock;
include /etc/nginx/mime.types;
}
}```

Nginx 403 Forbidden Even After Setting The Permission

I want to get Letsencrpyt SSL for my domain. Part of the process is, the site needs to be authorized before getting the certificate.
I created the folder ./well-known and ran the command I was asked to and I got;
Nginx 403 forbidden.
I'm on nginx/1.10.0 (Ubuntu)
I chown the directory and granted it 755 yet still the same. Check out the permissions in my directory below.
namei -l /var/www/example.com/.well-known
f: /var/www/example.com/.well-known
drwxr-xr-x root root /
drwxr-xr-x root root var
drwxr-xr-x root root www
drwxr-xr-x cman sudo example.com
drwxr-xr-x cman sudo .well-known
I also created a working.html file in the /.well-known folder and I load example.com/.well-known/working.html, I got the same 403 Forbidden.
Nginx.conf
upstream kip_app_server {
# fail_timeout=0 means we always retry an upstream even if it failed
# to return a good HTTP response (in case the Gunicorn master nukes a
# single worker for timing out).
server unix:/var/www/example.com/src/run/trav.sock fail_timeout=0;
}
server {
listen 80;
server_name example.com www.example.com;
location = /favicon.ico { access_log off; log_not_found off; }
access_log /var/www/example.com/logs/access.log;
error_log /var/www/example.com/logs/nerror.log;
charset utf-8;
client_max_body_size 75M;
location /static/ {
alias /var/www/example.com/src/static/;
}
location /media/ {
alias var/www/example.com/src/media/;
}
location ~ /\.well-known {
allow all;
alias /var/www/example.com/.well-known/;
}
location / {
include proxy_params;
proxy_pass http://kip_app_server;
#proxy_set_header X-Forwarded-Host $server_name;
#proxy_set_header X-Real-IP $remote_addr;
}
}
Your code would work if you were not using an alias.
Try this:
location ^~ /.well-known {
allow all;
alias /var/www/example.com/.well-known/;
}
or this:
location ^~ /.well-known {
allow all;
auth_basic off;
alias /path/to/.well-known/;
}
When aliasing, the ^ is required.
This is Nginx specific behaviour, to the way they perform matching. There is a detailed write-up here on matching logic and caveats, it is confusing: https://github.com/letsencrypt/acme-spec/issues/221
I tried but could not figure this out. I believe certbot is not getting the correct location and is probably writing the challenge to some other location. I had a script watching the acme challenge directory and nothing was ever created there. Ended by using the webroot option.
certbot certonly -d example.com -a webroot
It prompts for the webroot location, but only for the 1st time - not for renewal, which allows for auto-renewal. It may work without the certonly option, but I did not try it. I updated the NGINX config manually with the cert location.