最新消息:20210816 当前crifan.com域名已被污染,为防止失联,请关注(页面右下角的)公众号

【已解决】Ubuntu部署已有Django项目

项目 crifan 1198浏览 0评论
之前:
【未解决】本地搭建和部署运行Django项目
暂时还没彻底解决。
现在直接去,对于已有的Django代码,去在线服务器Ubuntu中部署。
尽快能运行起来再说。
对于pipenv虚拟环境的事情,以后再说。
先去把代码clone过去:
root@VM-158-80-ubuntu:~/xxx/xxx-backend# pwd
/root/xxx/xxx-backend
root@VM-158-80-ubuntu:~/xxx/xxx-backend# ll
total 52
drwxr-xr-x 7 root root 4096 Jun 24 20:01 ./
drwxr-xr-x 3 root root 4096 Jun 11 20:56 ../
drwxr-xr-x 2 root root 4096 Jun 11 20:57 app/
drwxr-xr-x 8 root root 4096 Jun 24 20:01 .git/
-rwxr-xr-x 1 root root  834 Jun 11 20:57 .gitignore*
drwxr-xr-x 2 root root 4096 Jun 11 20:57 libs/
-rwxr-xr-x 1 root root  809 Jun 11 20:57 manage.py*
-rw-r--r-- 1 root root  190 Jun 11 20:57 Pipfile
drwxr-xr-x 2 root root 4096 Jun 11 20:57 pywe_django/
-rwxr-xr-x 1 root root  638 Jun 24 20:01 README.md*
-rwxr-xr-x 1 root root   22 Jun 11 20:57 requirement.txt*
-rwxr-xr-x 1 root root   69 Jun 11 20:57 restart.sh*
drwxr-xr-x 3 root root 4096 Jun 11 20:57 wego/
然后参考
【整理】Django项目初始化流程
去初始化和部署
root@VM-158-80-ubuntu:~/xxx/xxx-backend# python3 manage.py migrate
Traceback (most recent call last):
  File "manage.py", line 22, in <module>
    execute_from_command_line(sys.argv)
  File "/usr/local/lib/python3.5/dist-packages/django/core/management/__init__.py", line 381, in execute_from_command_line
    utility.execute()
  File "/usr/local/lib/python3.5/dist-packages/django/core/management/__init__.py", line 375, in execute
    self.fetch_command(subcommand).run_from_argv(self.argv)
  File "/usr/local/lib/python3.5/dist-packages/django/core/management/__init__.py", line 224, in fetch_command
    klass = load_command_class(app_name, subcommand)
  File "/usr/local/lib/python3.5/dist-packages/django/core/management/__init__.py", line 36, in load_command_class
    module = import_module('%s.management.commands.%s' % (app_name, name))
  File "/usr/lib/python3.5/importlib/__init__.py", line 126, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "<frozen importlib._bootstrap>", line 986, in _gcd_import
  File "<frozen importlib._bootstrap>", line 969, in _find_and_load
  File "<frozen importlib._bootstrap>", line 958, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 673, in _load_unlocked
  File "<frozen importlib._bootstrap_external>", line 665, in exec_module
  File "<frozen importlib._bootstrap>", line 222, in _call_with_frames_removed
  File "/usr/local/lib/python3.5/dist-packages/django/core/management/commands/migrate.py", line 14, in <module>
    from django.db.migrations.autodetector import MigrationAutodetector
  File "/usr/local/lib/python3.5/dist-packages/django/db/migrations/autodetector.py", line 11, in <module>
    from django.db.migrations.questioner import MigrationQuestioner
  File "/usr/local/lib/python3.5/dist-packages/django/db/migrations/questioner.py", line 9, in <module>
    from .loader import MigrationLoader
  File "/usr/local/lib/python3.5/dist-packages/django/db/migrations/loader.py", line 8, in <module>
    from django.db.migrations.recorder import MigrationRecorder
  File "/usr/local/lib/python3.5/dist-packages/django/db/migrations/recorder.py", line 9, in <module>
    class MigrationRecorder:
  File "/usr/local/lib/python3.5/dist-packages/django/db/migrations/recorder.py", line 22, in MigrationRecorder
    class Migration(models.Model):
  File "/usr/local/lib/python3.5/dist-packages/django/db/models/base.py", line 87, in __new__
    app_config = apps.get_containing_app_config(module)
  File "/usr/local/lib/python3.5/dist-packages/django/apps/registry.py", line 249, in get_containing_app_config
    self.check_apps_ready()
  File "/usr/local/lib/python3.5/dist-packages/django/apps/registry.py", line 131, in check_apps_ready
    settings.INSTALLED_APPS
  File "/usr/local/lib/python3.5/dist-packages/django/conf/__init__.py", line 57, in __getattr__
    self._setup(name)
  File "/usr/local/lib/python3.5/dist-packages/django/conf/__init__.py", line 44, in _setup
    self._wrapped = Settings(settings_module)
  File "/usr/local/lib/python3.5/dist-packages/django/conf/__init__.py", line 107, in __init__
    mod = importlib.import_module(self.SETTINGS_MODULE)
  File "/usr/lib/python3.5/importlib/__init__.py", line 126, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "/root/xxx/xxx-backend/pywe_django/settings.py", line 15, in <module>
    import qiniu
ImportError: No module named 'qiniu'
找不到qiniu
去试试:
pip3 install qiniu
log:
root@VM-158-80-ubuntu:~/xxx/xxx-backend# pip3 install qiniu
Collecting qiniu
  Downloading https://files.pythonhosted.org/packages/2f/7e/e043e8e4adb31d1f0f9e48b3d9bbf83d08d9731b98eddb64974204d5e886/qiniu-7.2.4.tar.gz
Requirement already satisfied: requests in /usr/lib/python3/dist-packages (from qiniu) (2.9.1)
Building wheels for collected packages: qiniu
  Building wheel for qiniu (setup.py) ... done
  Stored in directory: /root/.cache/pip/wheels/c9/91/c0/a4edb7c92d3b5f419bb710e357132f79b400f9041b6f8298d6
Successfully built qiniu
Installing collected packages: qiniu
Successfully installed qiniu-7.2.4
然后继续试试:
python3 manage.py migrate
结果找不到数据库:
...
    err.raise_mysql_exception(self._data)
  File "/usr/local/lib/python3.5/dist-packages/pymysql/err.py", line 109, in raise_mysql_exception
    raise errorclass(errno, errval)
django.db.utils.InternalError: (1049, "Unknown database 'xxx'")
所以要先去新建数据库:
先去登录mysql
mysql -u root -p
再执行:
CREATE DATABASE `xxx` DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci;
注:
可通过:
show databases;
查看的确已新建数据库。
其中:
pywe_django/settings.py
DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.mysql',
        'NAME': 'xxx',
...
然后继续:
root@VM-158-80-ubuntu:~/xxx/xxx-backend# python3 manage.py migrate
Operations to perform:
  Apply all migrations: admin, auth, contenttypes, sessions
Running migrations:
  Applying contenttypes.0001_initial... OK
  Applying auth.0001_initial... OK
  Applying admin.0001_initial... OK
  Applying admin.0002_logentry_remove_auto_add... OK
  Applying admin.0003_logentry_add_action_flag_choices... OK
  Applying contenttypes.0002_remove_content_type_name... OK
  Applying auth.0002_alter_permission_name_max_length... OK
  Applying auth.0003_alter_user_email_max_length... OK
  Applying auth.0004_alter_user_username_opts... OK
  Applying auth.0005_alter_user_last_login_null... OK
  Applying auth.0006_require_contenttypes_0002... OK
  Applying auth.0007_alter_validators_add_error_messages... OK
  Applying auth.0008_alter_user_username_max_length... OK
  Applying auth.0009_alter_user_last_name_max_length... OK
  Applying sessions.0001_initial... OK
用uwsgi启动之前,先去看看配置文件是否需要更新:
结果项目中并没有:
uwsgi.ini
这个文件。
django uwsgi –ini uwsgi.ini
使用uWSGI和nginx来设置Django和你的web服务器 — uWSGI 2.0 文档
Setting up Django and your web server with uWSGI and nginx — uWSGI 2.0 documentation
Django UWSGI设置(上线部署) – 简书
How to use Django with uWSGI | Django documentation | Django
Django + uWSGI部署 · 夜露
nginx+uwsgi部署Django | nMask’s Blog
不过部署之前,好像需要生成静态文件?
先不管,以后遇到问题,再说。
服务器中去试试:
python3 manage.py runserver 0.0.0.0:8899
看看本地是否能跑起来。
root@VM-158-80-ubuntu:~/xxx/xxx-backend# python3 manage.py runserver 0.0.0.0:8899
Performing system checks...


System check identified no issues (0 silenced).
June 24, 2019 - 20:17:38
Django version 2.1, using settings 'pywe_django.settings'
Starting development server at http://0.0.0.0:8899/
Quit the server with CONTROL-C.
貌似可以?
再去拷贝:
brand.py
car.json
series.py
再去:
python3 manage.py shell

python3 brand.py
python3 series.py
结果都不对:
root@VM-158-80-ubuntu:~/xxx/xxx-backend# python3 manage.py shell
Python 3.5.2 (default, Nov 12 2018, 13:43:14)
[GCC 5.4.0 20160609] on linux
Type "help", "copyright", "credits" or "license" for more information.
(InteractiveConsole)
>>> python3 brand.py
Traceback (most recent call last):
  File "/usr/lib/python3.5/code.py", line 64, in runsource
    code = self.compile(source, filename, symbol)
  File "/usr/lib/python3.5/codeop.py", line 168, in __call__
    return _maybe_compile(self.compiler, source, filename, symbol)
  File "/usr/lib/python3.5/codeop.py", line 99, in _maybe_compile
    raise err1
  File "/usr/lib/python3.5/codeop.py", line 87, in _maybe_compile
    code1 = compiler(source + "\n", filename, symbol)
  File "/usr/lib/python3.5/codeop.py", line 133, in __call__
    codeob = compile(source, filename, symbol, self.flags, 1)
  File "<console>", line 1
    python3 brand.py
                ^
SyntaxError: invalid syntax
>>> brand.py        
Traceback (most recent call last):
  File "/usr/lib/python3.5/code.py", line 91, in runcode
    exec(code, self.locals)
  File "<console>", line 1, in <module>
NameError: name 'brand' is not defined
>>> python brand.py
Traceback (most recent call last):
  File "/usr/lib/python3.5/code.py", line 64, in runsource
    code = self.compile(source, filename, symbol)
  File "/usr/lib/python3.5/codeop.py", line 168, in __call__
    return _maybe_compile(self.compiler, source, filename, symbol)
  File "/usr/lib/python3.5/codeop.py", line 99, in _maybe_compile
    raise err1
  File "/usr/lib/python3.5/codeop.py", line 87, in _maybe_compile
    code1 = compiler(source + "\n", filename, symbol)
  File "/usr/lib/python3.5/codeop.py", line 133, in __call__
    codeob = compile(source, filename, symbol, self.flags, 1)
  File "<console>", line 1
    python brand.py
               ^
SyntaxError: invalid syntax
>>>
去试试别人说的
exec(open(xxxx.py).read())
exec(open(brand.py).read())
结果:
>>> exec(open(brand.py).read())
Traceback (most recent call last):
  File "/usr/lib/python3.5/code.py", line 91, in runcode
    exec(code, self.locals)
  File "<console>", line 1, in <module>
NameError: name 'brand' is not defined
那换用绝对路径:
exec(open(/root/xxx/xxx-backend/brand.py).read())
结果:
>>> exec(open(/root/xxx/xxx-backend/brand.py).read())
Traceback (most recent call last):
  File "/usr/lib/python3.5/code.py", line 64, in runsource
    code = self.compile(source, filename, symbol)
  File "/usr/lib/python3.5/codeop.py", line 168, in __call__
    return _maybe_compile(self.compiler, source, filename, symbol)
  File "/usr/lib/python3.5/codeop.py", line 99, in _maybe_compile
    raise err1
  File "/usr/lib/python3.5/codeop.py", line 87, in _maybe_compile
    code1 = compiler(source + "\n", filename, symbol)
  File "/usr/lib/python3.5/codeop.py", line 133, in __call__
    codeob = compile(source, filename, symbol, self.flags, 1)
  File "<console>", line 1
    exec(open(/root/xxx/xxx-backend/brand.py).read())
              ^
SyntaxError: invalid syntax
>>>
加上双引号:
exec(open("/root/xxx/xxx-backend/brand.py").read())
终于可以了。
...
度
...
YAMAHA
。。。
>>>
再去:
exec(open("/root/xxx/xxx-backend/series.py").read())
结果:
>>> exec(open("/root/xxx/xxx-backend/series.py").read())
Traceback (most recent call last):
  File "/usr/lib/python3.5/code.py", line 91, in runcode
    exec(code, self.locals)
  File "<console>", line 1, in <module>
  File "<string>", line 1, in <module>
ImportError: cannot import name 'CarModel'
然后去注释掉CarModel部分代码:
再去运行:
exec(open("/root/xxx/xxx-backend/series.py").read())
就可以了导入了。
然后再去访问接口,就可以了:
http://xxx:8899/api/car/series?id=1
把之前两个相关配置弄过来:
uwsgi_params
uwsgi_param QUERY_STRING        $query_string;
uwsgi_param REQUEST_METHOD      $request_method;
uwsgi_param CONTENT_TYPE        $content_type;
uwsgi_param CONTENT_LENGTH      $content_length;


uwsgi_param REQUEST_URI     $request_uri;
uwsgi_param PATH_INFO       $document_uri;
uwsgi_param DOCUMENT_ROOT       $document_root;
uwsgi_param SERVER_PROTOCOL     $server_protocol;
uwsgi_param UWSGI_SCHEME        $scheme;


uwsgi_param REMOTE_ADDR     $remote_addr;
uwsgi_param REMOTE_PORT     $remote_port;
uwsgi_param SERVER_PORT     $server_port;
uwsgi_param SERVER_NAME     $server_name;
uwsgi.ini
# setxcx_uwsgi.ini file
[uwsgi]


# Django-related settings
# the base directory (full path)
chdir           = /root/xxx/xxx-backend/
# Django's wsgi file
module          = pywe_django.wsgi
# the virtualenv (full path)


# process-related settings
# master
master          = true
# maximum number of worker processes
processes       = 15
# the socket (use the full path to be safe
socket          = /root/xxx/xxx-backend/socket.sock


# ... with appropriate permissions - may be needed
chmod-socket    = 664
# clear environment on exit
vacuum          = true
# pidfile
pidfile         = /root/xxx/xxx-backend/xxx.pid
# logger
daemonize       = /root/xxx/xxx-backend/access.log
然后再去看看nginx中配置
# nginx -t
nginx: [warn] the "ssl" directive is deprecated, use the "listen ... ssl" directive instead in /etc/nginx/conf.d/xxx.conf:7
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful
找到nginx的配置是:
/etc/nginx/nginx.conf
和:
/etc/nginx/
其中,看到之前配置:
    location /static/ {
        alias /root/xxx/static/;
    }
所以感觉此处需要:
再去生成static文件的
python3 manage.py collectstatic
结果:
# python3 manage.py collectstatic


You have requested to collect static files at the destination
location as specified in your settings.


This will overwrite existing files!
Are you sure you want to do this?


Type 'yes' to continue, or 'no' to cancel: no
CommandError: Collecting static files cancelled.
不管了,以后遇到问题再说。
另外,本地确认域名解析过来了:
➜  ~ ping xxx.xxx.com
PING xxx.xxx.com (xxx): 56 data bytes
64 bytes from xxx: icmp_seq=0 ttl=245 time=38.729 ms
去修改得到自己的nginx配置文件:
root@VM-158-80-ubuntu:/etc/nginx/conf.d# pwd
/etc/nginx/conf.d
root@VM-158-80-ubuntu:/etc/nginx/conf.d# ll
total 36
drwxrwxrwx 2 root   root   4096 Jun 24 22:02 ./
drwxr-xr-x 3 root   root   4096 Jun 18 21:21 ../
-rw-rw-r-- 1 root   root    316 Nov 14  2017 chandao.conf
-rw-r--r-- 1 root   root   1090 Jun 24 22:02 xxx.conf
-rw-r--r-- 1 root   root   1093 Apr 18  2018 default.conf
-rwxrwxrwx 1 root   root   1254 Jun  7  2017 faveo-helpdesk.conf*
-rw-r--r-- 1 root   root   1026 Aug 21  2018 xxx.conf
-rw-rw-r-- 1 root   root   4043 Nov 14  2017 nextcloud.conf
-rw-rw-r-- 1 ubuntu ubuntu 4039 Nov 17  2017 xxx_file.conf1
/etc/nginx/conf.d/xxx.conf
server {
    listen  80;
    server_name xxx.xxx.com;
    client_max_body_size 50m;
    listen 443;
    ssl on;
    ssl_certificate /root/xxx/chained.pem;
    ssl_certificate_key /root/xxx/xxx-ssl/2_xxx.xxx.com.key;
    ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
    ssl_prefer_server_ciphers on;
    ssl_session_timeout 10m;
    ssl_session_cache shared:SSL:10m;
    ssl_stapling on;
    ssl_stapling_verify on;
    ssl_trusted_certificate /root/xxx/xxx-ssl/1_xxx.xxx.com_bundle.crt;
    location ^~ /.well-known/acme-challenge/ {
        alias /root/xxx/challenges/;
        try_files $uri =404;
    }
    location /static/ {
        alias /root/xxx/xxx-backend/static/;
    }
    location / {
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        uwsgi_pass xxx;
        include /root/xxx/xxx-backend/uwsgi_params;
    }
    access_log /var/log/nginx/xxx.xxx.com_access.log;
    error_log /var/log/nginx/xxx.xxx.com_error.log;
}


upstream xxx {
    server unix:///root/xxx/xxx-backend/socket.sock;
}
去试试效果,结果报错:
【未解决】nginx的ssl证书报错:emerg SSL_CTX_use_PrivateKey key failed SSL error 0B080074 x509 certificate routines X509_check_private_key key values mismatch
继续部署:
# uwsgi --ini uwsgi.ini
[uWSGI] getting INI configuration from uwsgi.ini
# ll
total 600
drwxr-xr-x 7 root root   4096 Jun 24 22:24 ./
drwxr-xr-x 4 root root   4096 Jun 24 21:53 ../
-rw-r----- 1 root root   2619 Jun 24 22:24 access.log
drwxr-xr-x 4 root root   4096 Jun 24 20:55 app/
-rwxr-xr-x 1 root root  49282 Jun 24 21:11 brand.py*
-rwxr-xr-x 1 root root 479041 Jun 24 21:11 car.json*
-rw-rw-rw- 1 root root      4 Jun 24 22:24 xxx.pid
drwxr-xr-x 8 root root   4096 Jun 24 21:39 .git/
-rwxr-xr-x 1 root root    834 Jun 11 20:57 .gitignore*
drwxr-xr-x 3 root root   4096 Jun 24 20:09 libs/
-rwxr-xr-x 1 root root    809 Jun 11 20:57 manage.py*
-rw-r--r-- 1 root root    190 Jun 11 20:57 Pipfile
drwxr-xr-x 3 root root   4096 Jun 24 20:57 pywe_django/
-rwxr-xr-x 1 root root   1336 Jun 24 21:29 README.md*
-rwxr-xr-x 1 root root     22 Jun 11 20:57 requirement.txt*
-rwxr-xr-x 1 root root     69 Jun 11 20:57 restart.sh*
-rwxr-xr-x 1 root root    690 Jun 24 21:29 series.py*
srw-rw-r-- 1 root root      0 Jun 24 22:24 socket.sock=
-rw-r--r-- 1 root root    696 Jun 24 21:39 uwsgi.ini
-rw-r--r-- 1 root root    586 Jun 24 21:39 uwsgi_params
drwxr-xr-x 3 root root   4096 Jun 11 20:57 wego/
可以看到新生成了对应文件:
access.log
socket.sock=
xxx.pid
然后:
root@VM-158-80-ubuntu:~/xxx/xxx-backend# ps -ef|grep uwsgi
root       507     1  0 22:24 ?        00:00:00 uwsgi --ini uwsgi.ini
root       511   507  0 22:24 ?        00:00:00 uwsgi --ini uwsgi.ini
root       512   507  0 22:24 ?        00:00:00 uwsgi --ini uwsgi.ini
root       513   507  0 22:24 ?        00:00:00 uwsgi --ini uwsgi.ini
root       514   507  0 22:24 ?        00:00:00 uwsgi --ini uwsgi.ini
root       515   507  0 22:24 ?        00:00:00 uwsgi --ini uwsgi.ini
root       516   507  0 22:24 ?        00:00:00 uwsgi --ini uwsgi.ini
root       517   507  0 22:24 ?        00:00:00 uwsgi --ini uwsgi.ini
root       518   507  0 22:24 ?        00:00:00 uwsgi --ini uwsgi.ini
root       519   507  0 22:24 ?        00:00:00 uwsgi --ini uwsgi.ini
root       520   507  0 22:24 ?        00:00:00 uwsgi --ini uwsgi.ini
root       521   507  0 22:24 ?        00:00:00 uwsgi --ini uwsgi.ini
root       522   507  0 22:24 ?        00:00:00 uwsgi --ini uwsgi.ini
root       523   507  0 22:24 ?        00:00:00 uwsgi --ini uwsgi.ini
root       524   507  0 22:24 ?        00:00:00 uwsgi --ini uwsgi.ini
root       525   507  0 22:24 ?        00:00:00 uwsgi --ini uwsgi.ini
root      2156 22583  0 22:39 pts/1    00:00:00 grep --color=auto uwsgi
root     11922     1  0 May08 ?        00:03:16 uwsgi --ini uwsgi.ini
root     11925 11922  0 May08 ?        00:00:00 uwsgi --ini uwsgi.ini
root     11926 11922  0 May08 ?        00:00:00 uwsgi --ini uwsgi.ini
root     11927 11922  0 May08 ?        00:00:00 uwsgi --ini uwsgi.ini
root     11928 11922  0 May08 ?        00:00:00 uwsgi --ini uwsgi.ini
root     11929 11922  0 May08 ?        00:00:00 uwsgi --ini uwsgi.ini
root     11930 11922  0 May08 ?        00:00:00 uwsgi --ini uwsgi.ini
root     11931 11922  0 May08 ?        00:00:00 uwsgi --ini uwsgi.ini
root     11932 11922  0 May08 ?        00:00:00 uwsgi --ini uwsgi.ini
root     11933 11922  0 May08 ?        00:00:00 uwsgi --ini uwsgi.ini
root     11934 11922  0 May08 ?        00:00:00 uwsgi --ini uwsgi.ini
root     11935 11922  0 May08 ?        00:00:00 uwsgi --ini uwsgi.ini
root     11936 11922  0 May08 ?        00:00:00 uwsgi --ini uwsgi.ini
root     11937 11922  0 May08 ?        00:00:00 uwsgi --ini uwsgi.ini
root     11938 11922  0 May08 ?        00:00:00 uwsgi --ini uwsgi.ini
root     11939 11922  0 May08 ?        00:00:00 uwsgi --ini uwsgi.ini
root     18318     1  0 Jun08 ?        00:01:05 /usr/local/bin/uwsgi --ini uwsgi.ini
root     18346 18318  0 Jun08 ?        00:00:00 /usr/local/bin/uwsgi --ini uwsgi.ini
root     18347 18318  0 Jun08 ?        00:00:00 /usr/local/bin/uwsgi --ini uwsgi.ini
root     18348 18318  0 Jun08 ?        00:00:00 /usr/local/bin/uwsgi --ini uwsgi.ini
root     18349 18318  0 Jun08 ?        00:00:00 /usr/local/bin/uwsgi --ini uwsgi.ini
root     18350 18318  0 Jun08 ?        00:00:00 /usr/local/bin/uwsgi --ini uwsgi.ini
root     18351 18318  0 Jun08 ?        00:00:00 /usr/local/bin/uwsgi --ini uwsgi.ini
root     18352 18318  0 Jun08 ?        00:00:00 /usr/local/bin/uwsgi --ini uwsgi.ini
root     18353 18318  0 Jun08 ?        00:00:00 /usr/local/bin/uwsgi --ini uwsgi.ini
root     18354 18318  0 Jun08 ?        00:00:00 /usr/local/bin/uwsgi --ini uwsgi.ini
root     18355 18318  0 Jun08 ?        00:00:00 /usr/local/bin/uwsgi --ini uwsgi.ini
root     18356 18318  0 Jun08 ?        00:00:00 /usr/local/bin/uwsgi --ini uwsgi.ini
root     18357 18318  0 Jun08 ?        00:00:00 /usr/local/bin/uwsgi --ini uwsgi.ini
root     18358 18318  0 Jun08 ?        00:00:00 /usr/local/bin/uwsgi --ini uwsgi.ini
root     18359 18318  0 Jun08 ?        00:00:01 /usr/local/bin/uwsgi --ini uwsgi.ini
root     18360 18318  0 Jun08 ?        00:00:02 /usr/local/bin/uwsgi --ini uwsgi.ini
root@VM-158-80-ubuntu:~/xxx/xxx-backend#
继续看看域名访问是否正常
http://xx.xxx.com/api/car/series?id=1
还真的通过域名访问api接口了。
试试https
https://xxx.xxx.com/api/car/series?id=1
结果:
也是可以的了。
再去试试相同接口其他参数
https://xxx.xxx.com/api/car/series?id=20
也是OK的
对应log
# cat access.log
*** Starting uWSGI 2.0.17.1 (64bit) on [Mon Jun 24 22:24:01 2019] ***
compiled with version: 5.4.0 20160609 on 21 August 2018 01:49:31
os: Linux-4.4.0-53-generic #74-Ubuntu SMP Fri Dec 2 15:59:10 UTC 2016
nodename: VM-158-80-ubuntu
machine: x86_64
clock source: unix
pcre jit disabled
detected number of CPU cores: 2
current working directory: /root/xxx/xxx-backend
writing pidfile to /root/xxx/xxx-backend/xxx.pid
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) ***
chdir() to /root/xxx/xxx-backend/
your processes number limit is 15145
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 /root/xxx/xxx-backend/socket.sock fd 3
uWSGI running as root, you can use --uid/--gid/--chroot options
*** WARNING: you are running uWSGI as root !!! (use the --uid flag) ***
Python version: 3.5.2 (default, Nov 12 2018, 13:43:14)  [GCC 5.4.0 20160609]
*** Python threads support is disabled. You can enable it with --enable-threads ***
Python main interpreter initialized at 0xbdaf30
uWSGI running as root, you can use --uid/--gid/--chroot options
*** WARNING: you are running uWSGI as root !!! (use the --uid flag) ***
your server socket listen backlog is limited to 100 connections
your mercy for graceful operations on workers is 60 seconds
mapped 1166720 bytes (1139 KB) for 15 cores
*** Operational MODE: preforking ***
WSGI app 0 (mountpoint='') ready in 0 seconds on interpreter 0xbdaf30 pid: 507 (default app)
uWSGI running as root, you can use --uid/--gid/--chroot options
*** WARNING: you are running uWSGI as root !!! (use the --uid flag) ***
*** uWSGI is running in multiple interpreter mode ***
spawned uWSGI master process (pid: 507)
spawned uWSGI worker 1 (pid: 511, cores: 1)
spawned uWSGI worker 2 (pid: 512, cores: 1)
spawned uWSGI worker 3 (pid: 513, cores: 1)
spawned uWSGI worker 4 (pid: 514, cores: 1)
spawned uWSGI worker 5 (pid: 515, cores: 1)
spawned uWSGI worker 6 (pid: 516, cores: 1)
spawned uWSGI worker 7 (pid: 517, cores: 1)
spawned uWSGI worker 8 (pid: 518, cores: 1)
spawned uWSGI worker 9 (pid: 519, cores: 1)
spawned uWSGI worker 10 (pid: 520, cores: 1)
spawned uWSGI worker 11 (pid: 521, cores: 1)
spawned uWSGI worker 12 (pid: 522, cores: 1)
spawned uWSGI worker 13 (pid: 523, cores: 1)
spawned uWSGI worker 14 (pid: 524, cores: 1)
spawned uWSGI worker 15 (pid: 525, cores: 1)
[pid: 514|app: 0|req: 1/1] 114.219.21.127 () {40 vars in 766 bytes} [Mon Jun 24 22:26:00 2019] GET /api/car/series?id=1 => generated 1433 bytes in 28 msecs (HTTP/1.1 200) 3 headers in 102 bytes (1 switches on core 0)
Not Found: /favicon.ico
[pid: 512|app: 0|req: 1/2] 114.219.21.127 () {40 vars in 697 bytes} [Mon Jun 24 22:26:01 2019] GET /favicon.ico => generated 7388 bytes in 29 msecs (HTTP/1.1 404) 3 headers in 102 bytes (2 switches on core 0)
[pid: 520|app: 0|req: 1/3] 114.219.21.127 () {40 vars in 772 bytes} [Mon Jun 24 22:27:13 2019] GET /api/car/series?id=1 => generated 1433 bytes in 28 msecs (HTTP/1.1 200) 3 headers in 102 bytes (2 switches on core 0)
Not Found: /favicon.ico
[pid: 520|app: 0|req: 2/4] 114.219.21.127 () {40 vars in 704 bytes} [Mon Jun 24 22:27:13 2019] GET /favicon.ico => generated 7389 bytes in 7 msecs (HTTP/1.1 404) 3 headers in 102 bytes (2 switches on core 0)
[pid: 520|app: 0|req: 3/5] 114.219.21.127 () {40 vars in 772 bytes} [Mon Jun 24 22:28:01 2019] GET /api/car/series?id=5 => generated 108 bytes in 5 msecs (HTTP/1.1 200) 3 headers in 101 bytes (2 switches on core 0)
[pid: 523|app: 0|req: 1/6] 114.219.21.127 () {40 vars in 772 bytes} [Mon Jun 24 22:28:05 2019] GET /api/car/series?id=8 => generated 49 bytes in 29 msecs (HTTP/1.1 200) 3 headers in 100 bytes (2 switches on core 0)
[pid: 519|app: 0|req: 1/7] 114.219.21.127 () {40 vars in 774 bytes} [Mon Jun 24 22:28:09 2019] GET /api/car/series?id=20 => generated 749 bytes in 31 msecs (HTTP/1.1 200) 3 headers in 101 bytes (2 switches on core 0)
root@VM-158-80-ubuntu:~/xxx/xxx-backend#

转载请注明:在路上 » 【已解决】Ubuntu部署已有Django项目

发表我的评论
取消评论

表情

Hi,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址
80 queries in 0.191 seconds, using 22.19MB memory