I am using linux fedora, i installed nginx as sudo yum install nginx.I have created a django project and assigned a port as guicorn projectname.wsgi:application --bind=127.0.0.1:8001.And i created a file in /etc/nginx/sites-enabled/default
in my default file i have the following code:
server {
listen localhost:8006;
location / {
proxy_pass http://127.0.0.1:8001;
}
location /static/ {
autoindex on;
alias /home/user/Desktop/projects/28-05-2014/HMS/static/;
}
}
When i checked my nginx server home as localhost:80 it is running.But when i called localhost:8006 it is not connecting. When i checked active connections with netstat -lnt | grep 80 i found only nginx default service is running.What mistake i am doing.Any help would be appriciated
Place the above code in nginx.conf file which is located in /etc/nginx/.Then your configuration file looks like this
nginx.conf
server {
listen localhost:8006;
location / {
proxy_pass http://127.0.0.1:8001;
}
location /static/ {
autoindex on;
alias /home/user/Desktop/projects/28-05-2014/HMS/static/;
}
}
Not enough information to answer.
Enable logging:
access_log /var/log/nginx/example.access.log;
error_log /var/log/nginx/example.error.log;
And look at what the log files says. If you cannot figure it out, please post the log outputs here. Question does not provide enough data. I ll update this answer as you update your question.
Related
When I visit "localhost/media/media.png" it returns 404 but the file already exists in the folder. How can I solve the problem?
I am learning Python and I want to build a website with nginx, uwsgi and django so I read the official tutorial on https://uwsgi-docs.readthedocs.io/en/latest/tutorials/Django_and_nginx.html?highlight=django to configurate the my web server. But I got into trouble when I "Configure nginx for your site". The tutorial doesn't seem to work on my computer.
python version: 2.7.15rc1
nginx version: 1.14.0(Ubuntu)
django version: 1.11.20
# cs_community_site_nginx.conf
upstream django {
server 127.0.0.1:8001;
}
server {
listen 8000;
server_name 10.**.**.231; #
charset utf-8;
client_max_body_size 75M;
location /media {
alias /mnt/c/Users/duyu0/Documents/starfire/cs_community/cs_community_server/cs_community_site/media;
}
location /static {
alias /mnt/c/Users/duyu0/Documents/starfire/cs_community/cs_community_server/cs_community_site/static;
}
location / {
uwsgi_pass django;
include /mnt/c/Users/duyu0/Documents/starfire/cs_community/cs_community_server/cs_community_site/uwsgi_params;
}
}
I have a ruby file index.rb that contains puts "this is to show in nginx landing page".
My nginx landing location is /usr/share/nginx/html and my configuration is
server {
listen 80 default_server;
listen [::]:80 default_server ipv6only=on;
root /usr/share/nginx/html;
index index.rb index.html index.htm;
server_name localhost;
}
How do I print those lines without ruby on rails or python django? Do I need to build my code?
Nginx cannot run the index.rb script, in part because it does not have an embedded ruby (or python) interpreter. What you might want to do is to run your script through a uWSGI app. As documented here, for ruby, you need to create an app.ru script with a call entry point (which will just load your index.rb script). It is then run via:
uwsgi --socket 127.0.0.1:3031 --rack app.ru
Your nginx server can then access the uWSGI process with the following configuration:
location / {
include uwsgi_params;
uwsgi_pass 127.0.0.1:3031;
uwsgi_modifier1 7;
}
I have an nginx server with the configuration I want to be able to develop with a new address "hooks.devel.nclab.com" (vim /etc/nginx/sites-available/devel.nclab.com):
server {
listen 443 ssl;
ssl_certificate /etc/nginx/ssl-keys/devel.nclab.crt;
ssl_certificate_key /etc/nginx/ssl-keys/devel.nclab.key;
set $hook_home /home/labdevel/core/static/hooks;
root $hook_home;
server_name hooks.devel.nclab.com;
location ~ (\.py|\.sh)${
gzip off;
root $hook_home;
autoindex on;
fastcgi_pass unix:/var/run/fcgiwrap.socket;
include /etc/nginx/fastcgi_params;
fastcgi_param DOCUMENT_ROOT $hook_home;
fastcgi_param SCRIPT_FILENAME $hook_home$fastcgi_script_name;
}
}
I've created a simple python file to the directory given as $hook_home as "hello.py".
print "hello"
When I type "https://hooks.devel.nclab.com:443/hello.py" in the browser and give my user and password it says: "404: Not Found".
Where do I mess up the code?
Thank you for your help in advance.
Configuring nginx with the module
All you need is to change start command to
: static module
./configure --add-module=/path/to/nginx-python-module
: dynamic module
./configure --add-dynamic-module=/path/to/nginx-python-module
: sync-only version
./configure --add-module=/path/to/nginx-python-module
--with-cc-op=-DNGX_PYTHON_SYNC=1
: the path to python-config prior to configuring
export PYTHON_CONFIG=/path/to/python-config
I'm running my django project on amazon AMI machine and have problem with nginx serving static files. Project static folder path is /home/user/projectname/app/static and nginx.conf is
server {
listen 80;
location /static {
alias /home/user/projectname/app/static;
}
location / {
proxy_pass http://localhost:8000;
}
I tried to make collectstatic and change static location to alias /home/user/static; but it didn't help. What am i doing wrong?
Make sure that you chown the home directory. This makes the static files accessible to nginx.
chown -R user:user /home
chmod -R ug+r /home
Also, try running python manage.py collectstatic --noinput
Hope this solves the problem.
please change the static directory into staticstorage
server {
listen 80;
location /static {
alias /home/user/projectname/app/staticstorage;
}
location / {
proxy_pass http://localhost:8000;
}
I am stuck with setting the https with django on aws with nginx and gunicorn.
my configuration is:
server {
listen 80;
listen 443 ssl;
server_name logitech.enterpriselist.com;
rewrite ^ https://logitech.enterpriselist.com$request_uri? permanent;
root /home/ubuntu/git/elist/static/;
#` ssl on;
ssl_certificate /etc/ssl/elist.crt;
ssl_certificate_key /etc/ssl/elist.key;
location / {
# proxy_pass http://logitech.enterpriselist.com/;
}
location /static/ {
alias /home/ubuntu/git/elist/static/;
}
}
It is working fine with http with port 8001:
gunicorn configs.wsgi:application --bind 172.31.14.102:8001`
and not with domain
http://logitech.enterpriselist.com:8001/.
But I also want to run the things with the default port, but when I run
gunicorn configs.wsgi:application --bind 172.31.14.102:80
it says address already in use!
Also with https when I open http://logitech.enterpriselist.com/, it goes to https://logitech.enterpriselist.com/ but it says website have redirect loop so I need help in sorting this.
You haven't got anything to tell nginx it should be proxying requests to gunicorn. In particular, you need a proxy_pass directive and an upstream section.
Also, you don't want to run gunicorn on port 80, since that is what nginx is already bound to. That's what the proxy is for.
The gunicorn deployment docs have an example nginx configuration which works fine.