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
Related
I am having this test file called test.py:
def application(env, start_response):
start_response('200 OK', [('Content-Type','text/html')])
return [b"Hello World"]
and I run uWSGI using this command:
uwsgi --http :8001 --wsgi-file test.py
I am able to see the "Hello World" in browser by going to xxxx.xxxx.xxxx.xxxx:8001
Now I am trying to add Nginx to this. Here is my file called 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
listen 8000 default_server;
# the domain name it will serve for
server_name _;
charset utf-8;
# max upload size
client_max_body_size 75M; # adjust to taste
location /static {
alias /home/wz/dispatcher/OurAwesomeDjangoApp/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/wz/dispatcher/OurAwesomeDjangoApp/uwsgi_params; # the uwsgi_params file you installed
}
}
When i go to xxxx.xxxx.xxxx.xxxx I see the standard "Welcome to Nginx".
However when I go to xxxx.xxxx.xxxx.xxxx:8000 I am unable to connect.
Django server works on this port python manage.py runserver 0.0.0.0:8000 though.
uwsgi_params is present in my project directory.
I have also created a symlink to /etc/nginx/sites-enabled
What am i missing? Any help appreciated.
EDIT:
When i installed nginx using yum install nginx there were no sites-available and sites-enabled directories in /etc/nginx/.
I created them manually and added:
include /etc/nginx/sites-enabled/*;
to /etc/nginx/nginx.conf
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 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.
Hi I am new with nginx server, and I have uploaded my index.py file at /var/www/pyth/index.py ...
I am a little bit confused because in my local I can run freely
python index.py and access http://127.0.0.1:8080
I was wondering how can I do that in nginx, I have run python index.py but I can't access to mysite.com:8080
this is my config in /etc/nginx/sites-available/default
server {
listen 80 default_server;
listen [::]:80 default_server ipv6only=on;`
#root /usr/share/nginx/html;
#index index.php index.py index.html index.htm;
root /var/www/mysite.com;
index index.php index.py index.html index.htm;
# Make site accessible from http://localhost/
server_name mysite.com;
location / {
# First attempt to serve request as file, then
# as directory, then fall back to displaying a 404.
try_files $uri $uri/ =404;
# Uncomment to enable naxsi on this location
# include /etc/nginx/naxsi.rules
}
# Only for nginx-naxsi used with nginx-naxsi-ui : process denied reques$
#location /RequestDenied {
# proxy_pass http://127.0.0.1:8080;
#}
#error_page 404 /404.html;
...
does anyone has an idea about my case? any help will be appreciated.. thanks in advance
You should set up either a uwsgi (or similar), or a proxy_pass in nginx.
The option with UWSGI is better because it'll use the protocol designed for working with web-servers; though it's a bit harder to set up than just proxying everything via nginx.
proxy_pass
web.py has a web-server just for the development purposes, it shouldn't be used in production environment because it's really slow and inefficient in that case, and using proxy_pass wouldn't be a great idea if you are planning to release it.
With proxy_pass, you leave the 127.0.0.1:8080 server online, and then in nginx (on the same server), set up like that:
location / {
proxy_pass http://127.0.0.1:8080;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header Host $host;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
The proxy_pass option redirects everything to the web.py server at 127.0.0.1:8080, the other ones - redirect the data about the connection (IP of the connected client and the host that was used for the connection on the nginx's side)
UWSGI
Using UWSGI, in short, is like that:
1) install uwsgi using your distro's package manager, or a pip, or using setup.py install.
2) in nginx, set up a server that will pass everything to the UWSGI server:
server {
listen 80;
location / {
include uwsgi_params;
uwsgi_pass 127.0.0.1:9000;
}
}
3) Then, in your web.py application (let's suppose it's called yourappfile.py), instead of app.run(), use:
app = web.application(urls, globals())
application = app.wsgifunc()
You can still have app.run(), just make sure to put it inside the if __name__ == '__main__' block; and make sure the application = app.wsgifunc() is outside so UWSGI could see it.
Then start a UWSGI server:
uwsgi --http :9090 --wsgi-file yourappfile.py
Take a look at these manuals, it may help you:
UWSGI Quickstart
Web.py running on the nginx uwsgi
Deployment of Web.py Applications Using uWSGI and
Nginx
UWSGI Wiki - Examples
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.