Basic uwsgi configuration with Linode - python-2.7

I am following a tutorial on configuring Django, nginx and uwsgi.
https://gist.github.com/evildmp/3094281
The first part of which involves configuring uwsgi to run this python file
/home/ofey/djangoenv/bin/test.py
def application(env, start_response):
start_response('200 OK', [('Content-Type','text/html')])
return "Hello world"
djangoenv is the virtualenv directory.
It contains the binary uwsgi, which was installed to this environment using
$ pip install uwsgi
Just to note, I have stopped nginx with,
$ sudo systemctl stop nginx
and also stopped uwsgi which was running as a service with systemd.
$ sudo systemctl stop uwsgi
Running test.py and the output,
(djangoenv) [ofey#ofeyspi bin]$ uwsgi --http :8000 --master --wsgi-file test.py
*** Starting uWSGI 2.0.14 (64bit) on [Tue Nov 29 21:54:09 2016] ***
compiled with version: 6.2.1 20160916 (Red Hat 6.2.1-2) on 28 November 2016 14:39:40
os: Linux-4.8.6-x86_64-linode78 #1 SMP Tue Nov 1 14:51:21 EDT 2016
nodename: ofeyspi
machine: x86_64
clock source: unix
detected number of CPU cores: 1
current working directory: /home/ofey/djangoenv/bin
detected binary path: /home/ofey/djangoenv/bin/uwsgi
!!! no internal routing support, rebuild with pcre support !!!
your processes number limit is 7982
your memory page size is 4096 bytes
detected max file descriptor number: 1024
lock engine: pthread robust mutexes
thunder lock: disabled (you can enable it with --thunder-lock)
uWSGI http bound on :8000 fd 4
uwsgi socket 0 bound to TCP address 127.0.0.1:41335 (port auto-assigned) fd 3
Python version: 2.7.12 (default, Sep 29 2016, 13:30:34) [GCC 6.2.1 20160916 (Red Hat 6.2.1-2)]
*** Python threads support is disabled. You can enable it with --enable-threads ***
Python main interpreter initialized at 0xb72990
your server socket listen backlog is limited to 100 connections
your mercy for graceful operations on workers is 60 seconds
mapped 145520 bytes (142 KB) for 1 cores
*** Operational MODE: single process ***
WSGI app 0 (mountpoint='') ready in 0 seconds on interpreter 0xb72990 pid: 11493 (default app)
*** uWSGI is running in multiple interpreter mode ***
spawned uWSGI master process (pid: 11493)
spawned uWSGI worker 1 (pid: 11494, cores: 1)
spawned uWSGI http 1 (pid: 11495)
I would expect to see 'hello world' at http://qqiresources.com:8000
but nothing.
I do know that qqiresources.com is working because I see the nginx default homepage when I turn on nginx.
This is running on Linode with a virtual deployment of Fedora 24.
I did previously post a question trying to configure Django, wsgi and nginx on Linode but I think I need to figure out the above simpler situation first.
Linode Django uwsgi Nginx
Any help would be greatly appreciated,
Thanks

Related

How can I get uwsgi quickstart 'Hello World' to work on Digital Ocean?

The reason I asked this question is that every other question regarding the subject that I have seen on Stack Overflow is more complicated than mine. I am not trying to get uwsgi to work with anything else. I am simply trying to get the most basic implementation of it to actually do something.
I am following these instructions:
https://uwsgi-docs.readthedocs.io/en/latest/WSGIquickstart.html
My domain is called "prosaurus.com" and It's registered on Godaddy. I have hosting through Digital Ocean which has provided me with the following IP address: 143.198.142.59
In Digital Ocean I have set up two A records to point to the associated droplet/IP address. One is for "prosuaurus.com" the other is for "*.prosuarus.com"
I have followed the instructions exactly, opting for PIP to install uwsgi (as opposed to using wget and make).
I have created a file called 'foobar.py' as suggested and entered the suggested contents.
I have started the server as suggested on port 9090. This is the output I get:
uwsgi --http :9090 --wsgi-file foobar.py
*** Starting uWSGI 2.0.20 (64bit) on [Wed Sep 7 16:45:00 2022] ***
compiled with version: 11.2.0 on 02 September 2022 19:04:11
os: Linux-5.15.0-47-generic #51-Ubuntu SMP Thu Aug 11 07:51:15 UTC 2022
nodename: ubuntu-s-1vcpu-1gb-intel-sfo3-01
machine: x86_64
clock source: unix
detected number of CPU cores: 1
current working directory: /home/deployer
detected binary path: /home/deployer/.local/bin/uwsgi
!!! no internal routing support, rebuild with pcre support !!!
*** WARNING: you are running uWSGI without its master process manager ***
your processes number limit is 3721
your memory page size is 4096 bytes
detected max file descriptor number: 1024
lock engine: pthread robust mutexes
thunder lock: disabled (you can enable it with --thunder-lock)
uWSGI http bound on :9090 fd 4
spawned uWSGI http 1 (pid: 59211)
uwsgi socket 0 bound to TCP address 127.0.0.1:46629 (port auto-assigned) fd 3
Python version: 3.10.4 (main, Jun 29 2022, 12:14:53) [GCC 11.2.0]
*** Python threads support is disabled. You can enable it with --enable-threads ***
Python main interpreter initialized at 0x55b300c4fb30
your server socket listen backlog is limited to 100 connections
your mercy for graceful operations on workers is 60 seconds
mapped 72920 bytes (71 KB) for 1 cores
*** Operational MODE: single process ***
WSGI app 0 (mountpoint='') ready in 0 seconds on interpreter 0x55b300c4fb30 pid: 59210 (default app)
*** uWSGI is running in multiple interpreter mode ***
spawned uWSGI worker 1 (and the only) (pid: 59210, cores: 1)
oba
Everything appears to have worked correctly. I saw no error messages in any of the above steps (There was one warning suggesting I should use a virtual environment but this was just a warning right?)
yet, I do not see my hello world page. I don't see it on http://prosaurus.com:9090 or http://www.prosaurus.com:9090 or http://143.198.142.59:9090
What could I have possibly missed?
Side note: This server does have nginx installed on it, however I specifically turned it off before this test.
Firewall...
sudo ufw allow 9090
It would have been nice if they had mentioned this possibility in the docs.

uWSGI runs Python 2 with Plugin Python36 -> doesn't find Django in Venv

I'm trying to setup a simple Django project with Nginx, uWSGI on my Centos7-Server with this Tutorial:
How to Serve Django Applications with uWSGI and Nginx on CentOS 7
But I've tried to change this project into running Django 2 with Python 3.6
Everything worked pretty well, till creating firstsite.ini file.
1 [uwsgi]
2 project = firstsite
3 username = user
4 base = /home/%(username)
5 plugins-dir = /usr/lib64/uwsgi/
6 plugin = python36
7 virtualenv = %(base)/Env/%(project)
8 chdir = %(base)/%(project)
9 home = %(base)/Env/%(project)
10 module = %(project).wsgi:application
11
12 master = true
13 processes = 5
14
15 uid = %(username)
16 socket = /run/uwsgi/%(project).sock
17 chown-socket = %(username):nginx
18 chmod-socket = 660
19 vacuum = true
There I got stuck into. While setting up and trying to reach the Django Site I got an Internal Server Error. After checking error-log files and messages, I've implemented logto into my .ini file::
21 #Error Logs
22 logto = %(base)/%(project)/error.log
after checking this file it tells me this Error-Message::
*** Starting uWSGI 2.0.18 (64bit) on [Wed Aug 14 13:27:24 2019] ***
compiled with version: 4.8.5 20150623 (Red Hat 4.8.5-36) on 23 July 2019 10:27:56
os: Linux-3.10.0-957.21.3.el7.x86_64 #1 SMP Tue Jun 18 16:35:19 UTC 2019
nodename: ip-172-31-34-37.eu-central-1.compute.internal
machine: x86_64
clock source: unix
pcre jit disabled
detected number of CPU cores: 1
current working directory: /etc/uwsgi/sites
detected binary path: /usr/bin/uwsgi
chdir() to /home/user/firstsite
your processes number limit is 3775
your memory page size is 4096 bytes
detected max file descriptor number: 1024
lock engine: pthread robust mutexes
thunder lock: disabled (you can enable it with --thunder-lock)
uwsgi socket 0 bound to UNIX address /run/uwsgi/firstsite.sock fd 3
setuid() to 1001
Python version: 2.7.5 (default, Jun 20 2019, 20:27:34) [GCC 4.8.5 20150623 (Red Hat 4.8.5-36)]
Set PythonHome to /home/user/Env/firstsite
*** Python threads support is disabled. You can enable it with --enable-threads ***
Python main interpreter initialized at 0x234f0e0
your server socket listen backlog is limited to 100 connections
your mercy for graceful operations on workers is 60 seconds
mapped 437520 bytes (427 KB) for 5 cores
*** Operational MODE: preforking ***
Traceback (most recent call last):
File "./firstsite/wsgi.py", line 12, in <module>
from django.core.wsgi import get_wsgi_application
ImportError: No module named django.core.wsgi
unable to load app 0 (mountpoint='') (callable not found or import error)
*** no app loaded. going in full dynamic mode ***
*** uWSGI is running in multiple interpreter mode ***
spawned uWSGI master process (pid: 21976)
spawned uWSGI worker 1 (pid: 21978, cores: 1)
spawned uWSGI worker 2 (pid: 21979, cores: 1)
spawned uWSGI worker 3 (pid: 21980, cores: 1)
spawned uWSGI worker 4 (pid: 21981, cores: 1)
spawned uWSGI worker 5 (pid: 21982, cores: 1)
If I manually try to get this django project runing with the same Env, there is no problem. So I thought that it could be because of the fact that uwsgi is running Python 2.7.5 instead of Python 3.6.
I also checked the plugin python with uwsgi --plugin python36 -s:0
*** Starting uWSGI 2.0.18 (64bit) on [Thu Aug 15 04:16:19 2019] ***
compiled with version: 4.8.5 20150623 (Red Hat 4.8.5-36) on 14 August 2019 14:16:35
os: Linux-3.10.0-957.21.3.el7.x86_64 #1 SMP Tue Jun 18 16:35:19 UTC 2019
nodename: ip-172-31-34-37.eu-central-1.compute.internal
machine: x86_64
clock source: unix
pcre jit disabled
detected number of CPU cores: 1
current working directory: /usr/lib64/uwsgi
detected binary path: /usr/local/bin/uwsgi
*** WARNING: you are running uWSGI without its master process manager ***
your processes number limit is 3775
your memory page size is 4096 bytes
detected max file descriptor number: 1024
lock engine: pthread robust mutexes
thunder lock: disabled (you can enable it with --thunder-lock)
uwsgi socket 0 bound to TCP address :37796 (port auto-assigned) fd 3
Python version: 3.6.8 (default, Apr 25 2019, 21:02:35) [GCC 4.8.5 20150623 (Red Hat 4.8.5-36)]
*** Python threads support is disabled. You can enable it with --enable-threads ***
Python main interpreter initialized at 0x17756c0
your server socket listen backlog is limited to 100 connections
your mercy for graceful operations on workers is 60 seconds
mapped 72920 bytes (71 KB) for 1 cores
*** Operational MODE: single process ***
*** no app loaded. going in full dynamic mode ***
*** uWSGI is running in multiple interpreter mode ***
spawned uWSGI worker 1 (and the only) (pid: 6476, cores: 1)
So it looks to me, that I've created my 36-plugin the right way.
Would be really grateful if someone could help me out.
this is where the real problem is it can't find django
are you sure that django is installed in that environment you mentioned?
i mean "Env"
Traceback (most recent call last):
File "./firstsite/wsgi.py", line 12, in <module>
from django.core.wsgi import get_wsgi_application
ImportError: No module named django.core.wsgi
in that link you mentioned i couldn't find
virtualenv = %(base)/Env/%(project)
try changing it to
virtualenv = %(base)/Env
if that didnt solve your problem please specify django, python versions you are using plus your project structure

No module named 'django' uWSGI

in a nutshell I am getting the following error message from uWSGI when I try to test my installation against the examples found here:
$ uwsgi --socket 127.0.0.1:3031 --chdir /home/user/~Env/proj0/proj0 --wsgi-file wsgi.py --master --processes 4 --threads 2 --stats 127.0.0.1:9191
*** Starting uWSGI 2.0.15 (64bit) on [Wed May 31 14:10:35 2017] ***
compiled with version: 4.8.5 20150623 (Red Hat 4.8.5-11) on 30 May 2017 20:50:53
os: Linux-3.10.0-514.10.2.el7.x86_64 #1 SMP Fri Mar 3 00:04:05 UTC 2017
nodename: echo.com
machine: x86_64
clock source: unix
pcre jit disabled
detected number of CPU cores: 2
current working directory: /home/user/~Env
detected binary path: /usr/local/bin/uwsgi
chdir() to /home/user/~Env/proj0/proj0
your processes number limit is 4096
your memory page size is 4096 bytes
detected max file descriptor number: 1024
lock engine: pthread robust mutexes
thunder lock: disabled (you can enable it with --thunder-lock)
uwsgi socket 0 bound to TCP address 127.0.0.1:3031 fd 3
Python version: 3.6.1 (default, May 29 2017, 14:21:37) [GCC 4.8.5 20150623
(Red Hat 4.8.5-11)]
Python main interpreter initialized at 0x1639580
python threads support enabled
your server socket listen backlog is limited to 100 connections
your mercy for graceful operations on workers is 60 seconds
mapped 415360 bytes (405 KB) for 8 cores
*** Operational MODE: preforking+threaded ***
Traceback (most recent call last):
File "wsgi.py", line 12, in <module>
from django.core.wsgi import get_wsgi_application
ModuleNotFoundError: No module named 'django'
unable to load app 0 (mountpoint='') (callable not found or import error)
*** no app loaded. going in full dynamic mode ***
*** uWSGI is running in multiple interpreter mode ***
spawned uWSGI master process (pid: 20065)
spawned uWSGI worker 1 (pid: 20066, cores: 2)
spawned uWSGI worker 2 (pid: 20067, cores: 2)
spawned uWSGI worker 3 (pid: 20068, cores: 2)
spawned uWSGI worker 4 (pid: 20069, cores: 2)
*** Stats server enabled on 127.0.0.1:9191 fd: 15 ***
So obviously it found my wsgi.py file, but not Django. I'm not sure if I screwed up installing uWSGI system wide, my virtualenv folder layout, or whatever. I had wanted to deploy my app soon, but this takes precedence since I want to use nginx and uWSGI. My directory structure:
~Env---
projectenv proj0
bin proj0
include __init__.py
libs __pycache__
. settings.py
urls.py
views.py
wsgi.py
Any help at this point would be great. Thanks.
It doesn't look like it's using a Python interpreter that has Django installed, so it's probably not seeing your virtualenv.
Did you take the appropriate step to add your virtualenv to uwsgi options?
https://uwsgi-docs.readthedocs.io/en/latest/WSGIquickstart.html#virtualenvs

SyntaxError when quickstart for Python3/uWSGI

I wasted many time but couldn't find a solution. Ask for help.
I use ubuntu server 14.04, setup uwsgi by:
pip3 install uwsgi
Then I create the test.py:
def application(env, start_response):
start_response('200 OK', [('Content-Type','text/html')])
return [b"Hello World"]
After I run:
uwsgi --http :8001 --wsgi-file test.py
It shows:
*** Starting uWSGI 2.0.12 (64bit) on [Sat Mar 26 13:06:41 2016] ***
compiled with version: 4.8.4 on 26 March 2016 09:06:13
os: Linux-3.13.0-65-generic #106-Ubuntu SMP Fri Oct 2 22:08:27 UTC 2015
nodename: iZ282na6z2kZ
machine: x86_64
clock source: unix
pcre jit disabled
detected number of CPU cores: 1
current working directory: /home
detected binary path: /usr/local/bin/uwsgi
uWSGI running as root, you can use --uid/--gid/--chroot options
*** WARNING: you are running uWSGI as root !!! (use the --uid flag) ***
*** WARNING: you are running uWSGI without its master process manager ***
your processes number limit is 15834
your memory page size is 4096 bytes
detected max file descriptor number: 65535
lock engine: pthread robust mutexes
thunder lock: disabled (you can enable it with --thunder-lock)
uWSGI http bound on :8001 fd 4
spawned uWSGI http 1 (pid: 24498)
uwsgi socket 0 bound to TCP address 127.0.0.1:57629 (port auto-assigned) fd 3
Python version: 3.4.3 (default, Oct 14 2015, 20:31:36) [GCC 4.8.4]
*** Python threads support is disabled. You can enable it with --enable-threads ***
Python main interpreter initialized at 0x16fa3b0
your server socket listen backlog is limited to 100 connections
your mercy for graceful operations on workers is 60 seconds
mapped 72760 bytes (71 KB) for 1 cores
*** Operational MODE: single process ***
File "test.py", line 3
return [b'Hello World']
^
SyntaxError: invalid syntax
failed to parse file test.py
unable to load app 0 (mountpoint='') (callable not found or import error)
*** no app loaded. going in full dynamic mode ***
*** uWSGI is running in multiple interpreter mode ***
spawned uWSGI worker 1 (and the only) (pid: 24497, cores: 1)
Why there is a syntax error for python3?
P.S sorry for my English :P

Issue using supervisor and uwsgi in conda env

I'm trying to run a Flask app with uwsgi + supervisor + nginx.
uwsgi is installed in a conda env, and I can run my app with no issue without supervisor, i.e. if I run (with my conda env activated):
uwsgi --ini /home/me/Development/flask/myflaskapp/myflaskapp.ini
with the following config:
/home/me/Development/flask/myflaskapp/myflaskapp.ini
[uwsgi]
chmod-socket = 666
socket = /home/me/Development/flask/myflaskapp/run/myflaskapp.sock
module = wsgi
callable = app
vim /etc/nginx/sites-available/myflaskapp
server {
listen 8000;
server_name localhost;
client_max_body_size 50M;
location / {
include uwsgi_params;
uwsgi_pass unix:/home/me/Development/flask/myflaskapp/run/myflaskapp.sock;
}
}
Now I create a supervisor config file:
/etc/supervisor/conf.d/uwsgi-myflaskapp.conf
[program:uwsgi-myflaskapp]
command=/home/me/Development/miniconda/envs/myflaskapp/bin/uwsgi /home/me/Development/flask/myflaskapp/myflaskapp.ini
autostart=true
autorestart=true
stdout_logfile=/home/me/Development/flask/myflaskapp/log/uwsgi-myflaskapp.log
redirect_stderr=true
exitcodes=0
I start supervisor (installed system-wide) with
sudo service supervisor start
and load the conf file with
sudo supervisorctl reload
but I get the following error in the log file:
ImportError: No module named wsgi
Any suggestion?
Here's the complete log:
[uWSGI] getting INI configuration from /home/me/Development/flask/myflaskapp/myflaskapp.ini
*** Starting uWSGI 2.0.12 (64bit) on [Mon Jan 11 19:12:14 2016] ***
compiled with version: 4.8.4 on 11 January 2016 10:54:59
os: Linux-3.13.0-74-generic #118-Ubuntu SMP Thu Dec 17 22:52:10 UTC 2015
nodename: roquefort
machine: x86_64
clock source: unix
pcre jit disabled
detected number of CPU cores: 4
current working directory: /
detected binary path: /home/me/Development/miniconda/envs/myflaskapp/bin/uwsgi
uWSGI running as root, you can use --uid/--gid/--chroot options
*** WARNING: you are running uWSGI as root !!! (use the --uid flag) ***
*** WARNING: you are running uWSGI without its master process manager ***
your processes number limit is 63047
your memory page size is 4096 bytes
detected max file descriptor number: 1024
lock engine: pthread robust mutexes
thunder lock: disabled (you can enable it with --thunder-lock)
uwsgi socket 0 bound to UNIX address /home/me/Development/flask/myflaskapp/run/myflaskapp.sock fd 3
Python version: 2.7.11 |Continuum Analytics, Inc.| (default, Dec 6 2015, 18:08:32) [GCC 4.4.7 20120313 (Red Hat 4.4.7-1)]
*** Python threads support is disabled. You can enable it with --enable-threads ***
Python main interpreter initialized at 0x18001e0
your server socket listen backlog is limited to 100 connections
your mercy for graceful operations on workers is 60 seconds
mapped 72760 bytes (71 KB) for 1 cores
*** Operational MODE: single process ***
ImportError: No module named wsgi
unable to load app 0 (mountpoint='') (callable not found or import error)
*** no app loaded. going in full dynamic mode ***
*** uWSGI is running in multiple interpreter mode ***
spawned uWSGI worker 1 (and the only) (pid: 24671, cores: 1)
I added the the path of the wsgi.py file in /home/me/Development/flask/myflaskapp/myflaskapp.ini with
chdir = /home/me/Development/flask/myflaskapp
so that it can now find wsgi.