I am getting this error when trying to start nginx:
/$ sudo nginx -t
"nginx: [emerg] "upstream" directive is not allowed here in /etc/nginx/sites-enabled/catalog_nginx.conf:4"
I have this file "catalog_nginx.conf" located in the root of my app:
# catalog_nginx.conf
# the upstream component nginx needs to connect to
upstream django {
#server unix:///home/ec2-user/catalog/catalog.sock; # production
server 127.0.0.1:8001; # testing
}
# configuration of the server
server {
listen 8000;
server_name 54.redacted;
charset utf-8;
# max upload size
client_max_body_size 75M;
# Django media
location /media {
alias /home/ec2-user/catalog/media/; # media files
}
location /static {
alias /home/ec2-user/catalog/static/; # static files
}
# all non-media requests
location / {
uwsgi_pass django;
include /home/ec2-user/catalog/uwsgi_params;
}
}
In the 'nginx.conf' file from /etc/nginx/ I have the following under http{}
include /etc/nginx/conf.d/*.conf;
include /etc/nginx/sites-enabled/*.conf;
I have symlinked the two files.
Thoughts?
Related
I am trying to do the following.
I have 3 django projects (NOT apps) (can be more).
Proj1: On port 8000, Proj2: 8001, and Proj3:8002
This is what I am trying to achieve:
User visits : localhost:8000
All urls under Pr1: Respond
User visits: localhost:8000/Pr2
All urls under Pr2: Respond
User visits: localhost:8000/Pr3
All urls under Pr3: Respond
Goal: Proj 1 is run with Docker and Nginx. Now I have 2 new projects to integrate. Every new sub project should be reached using only one main port (8000). But internally the request is directed towards the correct port of sub-project.
Why this goal: Achieve micro-service style structure. Sub projects (2 & 3) can be reached only after authentication through Proj1.
What have I tried: Honestly no clear idea where to start.
Added new projects to docker-compose...they all work when visited by their own port(localhost:8001/Prj2) ..
With nginx, tried adding a new server. No effect:
server {
listen 8001;
location / {
proxy_pass http://web_socket:8080;
proxy_redirect off;
}
}
If you have "nginx" installed, so you can just create two files (site1.com.conf, site2.com.conf) in the following directory: "/etc/nginx/sites-enabled/"
Then add inside this files codes below:
site1.com.conf
# the upstream component nginx needs to connect to
upstream site1 {
# server unix:///path/to/your/mysite/mysite.sock; # for a file socket
server 127.0.0.1:49151; # for a web port socket (we'll use this first)
}
# configuration of the server
server {
# the port your site will be served on
listen 80;
# the domain name it will serve for
server_name site1.com; # substitute your machine's IP address or FQDN
charset utf-8;
# max upload size
client_max_body_size 75M; # adjust to taste
# Django media
location /media {
alias /var/www/site1.com/src/media; # your Django project's media files - amend as required
}
location /static {
alias /var/www/site1.com/src/static; # your Django project's static files - amend as required
}
# Finally, send all non-media requests to the Django server.
location / {
uwsgi_pass site1;
include /etc/nginx/uwsgi_params; # the uwsgi_params file you installed
}
}
site2.com.conf
# the upstream component nginx needs to connect to
upstream site2 {
# server unix:///path/to/your/mysite/mysite.sock; # for a file socket
server 127.0.0.1:49152; # for a web port socket (we'll use this first)
}
# configuration of the server
server {
# the port your site will be served on
listen 80;
# the domain name it will serve for
server_name site2.com; # substitute your machine's IP address or FQDN
charset utf-8;
# max upload size
client_max_body_size 75M; # adjust to taste
# Django media
location /media {
alias /var/www/site2.com/src/media; # your Django project's media files - amend as required
}
location /static {
alias /var/www/site2.com/src/static; # your Django project's static files - amend as required
}
# Finally, send all non-media requests to the Django server.
location / {
uwsgi_pass site2;
include /etc/nginx/uwsgi_params; # the uwsgi_params file you installed
}
}
Then edit "/etc/hosts" and add there two lines:
127.0.0.1 site1.com
127.0.0.1 site2.com
After saving files, restart uwsgi (install if it is not installed) and **nginx**
**service uwsgi restart**
**sudo /etc/init.d/nginx restart**
**Note: all your django applications should be in the folder of "/var/www/site1.com/src" and "/var/www/site2.com/src"**
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 am configuring for 1st time and getting this error.
Nginx site-enabled config is as follows:
#tream component nginx needs to connect to
upstream django1 {
#server 127.0.0.1:8001; # for a web port socket (we'll use this first)
server unix:///run/uwsgi/app/apps/sokcet.B;
}
# configuration of the server
server {
# the port your site will be served on
listen 9000;
# the domain name it will serve for
server_name xxx.xxx.xx.xxx; # substitute your machine's IP address or FQDN
charset utf-8;
# max upload size
client_max_body_size 75M; # adjust to taste
# Django media
#location /media {
# alias /path/to/your/mysite/media; # your Django project's media files - amend as required
#}
#location /static {
# alias /path/to/your/mysite/static; # your Django project's static files - amend as required
#}
# Finally, send all non-media requests to the Django server.
location / {
uwsgi_pass django1;
include /etc/nginx/uwsgi_params; # the uwsgi_params file you installed
uwsgi_read_timeout 1800;
uwsgi_send_timeout 600;
proxy_read_timeout 600;
}
}
Uwsgi is running but nginx is giving this error.
So kindly tell me what is the issue in my configuration.
I've been working through a turotial and got stuck at this specific part and can't seem to figure it out. This is exactly where I am stuck.
Here is my mysite_nginx.conf
# mysite_nginx.conf
# the upstream component nginx needs to connect to
upstream django {
# server unix:///path/to/your/mysite/mysite.sock; # for a file socket
server 127.0.0.1:8001; # for a web port socket (we'll use this first)
}
# configuration of the server
server {
# the port your site will be served on
root / ;
listen 8000;
# the domain name it will serve for
server_name .81.*.*.*; # substitute your machine's IP address or FQDN
charset utf-8;
# max upload size
client_max_body_size 75M; # adjust to taste
# Django media
location /media/ {
root /home/mysite/mysite1/blog/media; # your Django project's static files - amend as required
}
# Django static
location /static/ {
#alias /home/mysite/mysite1/blog/templates; # your Django project's media files - amend as required
root /home/mysite/mysite1/blog/static;
}
# Finally, send all non-media requests to the Django server.
location / {
uwsgi_pass django;
include /home/mysite/mysite1/uwsgi_params; # the uwsgi_params file you installed
}
}
Here is the file structure of mysite on pastebin - Sorry for it being a total mess. I am aware of redundant static files. If you need any other files, I am happy to provide. Thank you.
I'm very new to NGINX, or setting up a server in general. I'm going through the tutorial http://uwsgi-docs.readthedocs.org/en/latest/tutorials/Django_and_nginx.html with a website I'm trying to set up. I'm getting to the point in the tutorial where you use sockets, however, I can't get the socket to work. nginx.conf looks like this.
# the upstream component nginx needs to connect to
upstream django {
server unix:///home/althor/projects/Freebooks/freebooks.sock; # for a file socket
# server 127.0.0.1:8001; # for a web port socket (we'll use this first)
}
# configuration of the server
server {
# the port your site will be served on
listen 8000;
# the domain name it will serve for
server_name 10.0.0.130; # substitute your machine's IP address or FQDN
charset utf-8;
# max upload size
client_max_body_size 75M; # adjust to taste
# Django media
location /media {
alias /home/althor/projects/FreeBooks/media; # your Django project's media files - amend as required
}
location /static {
alias /home/althor/projects/FreeBooks/static; # your Django project's static files - amend as required
}
# Finally, send all non-media requests to the Django server.
location / {
uwsgi_pass django;
include /home/althor/projects/FreeBooks/uwsgi_params; # the uwsgi_params file you installed
}
}
The command i'm doing is this:
uwsgi --socket freebooks.sock --module FreeBooks.wsgi --chmod-socket=664
My File structure looks like this
-home
-projects
-FreeBooks
freebooks_nginx.conf
freebooks.sock=
-FreeBooks
wsgi
I'm not getting any type of error. When I go to 10.0.0.130, all I get is the welcome to nginx thing, same for 0.0.0.0, 127.0.0.1. Except when I got to port 8000 where I get a bad nginx gateway. Any help would be very much appreciated.
remove your "upstream django" line and replace your uwsgi_pass line with
uwsgi_pass unix:///home/althor/projects/Freebooks/freebooks.sock;
so that your file looks like
server {
listen 8000;
server_name 10.0.0.130; # substitute your machine's IP address or FQDN
charset utf-8;
client_max_body_size 75M; # adjust to taste
location /media {
alias /home/althor/projects/FreeBooks/media;
}
location /static {
alias /home/althor/projects/FreeBooks/static;
}
location / {
include /home/althor/projects/FreeBooks/uwsgi_params;
uwsgi_pass unix:///home/althor/projects/Freebooks/freebooks.sock;
}
}
Also make sure the socket file actually gets created when you run uwsgi command and that it is readable by the user running nginx (the properties are right but does the user have access to the full path?)
It turned out be a permissions issue. NGINX didn't have permission to write to the socket.