Deploy multiple projects on Ubuntu (using ngingo + Django server)

Empire my love 2022-05-14 14:55:26 阅读数:11

deploymultipleprojectsubuntuusing

The premise is already installed Nginx and uwsgi.
take Django Upload the project to the server .

On the project root , establish uWSGI Configuration file for uwsgi.ini.

Resume project -uwsgi.ini To configure

[uwsgi]
socket=:8000
# The address of the project on the server
chdir=/home/ubuntu/chenzhanxu/blog
module=resume.wsgi
master=true
processes=2
threads=2
vacuum=true
harakiri=120
buffer-size=65536
lazy-apps=true
# The virtual environment of the project
home=/home/ubuntu/.virtualenvs/chen

Personal blog project -uwsgi.ini To configure

[uwsgi]
# Open server port number
socket=:8001
# The address of the project on the server
chdir=/home/ubuntu/chenzhanxu/blog
module=blog.wsgi
master=true
processes=2
threads=2
vacuum=true
harakiri=120
buffer-size=65536
lazy-apps=true
# The virtual environment of the project
home=/home/ubuntu/.virtualenvs/chenzhanxu

As far as possible will ini The notes in the document are deleted , So as not to report a mistake .
uwsgi After configuring the file , And then configuration Nginx,Nginx The default configuration files are all in /etc/nginx Under the table of contents , So in /etc/nginx/sites-available Configure under Directory default file . 

sudo vim /etc/nginx/sites-available/default

I am the default All the contents of the file have been backed up ( In case you don't know the source file ), And then I deleted .

# First item configuration
server {
# SSL certificate
listen 443 ssl;
ssl_certificate /home/ubuntu/chenzhanxu/chenzhanxu.top_nginx/chenzhanxu.top_bundle.crt;
ssl_certificate_key /home/ubuntu/chenzhanxu/chenzhanxu.top_nginx/chenzhanxu.top.key;
ssl_session_timeout 5m;
ssl_protocols TLSv1.2 TLSv1.3;
ssl_ciphers ECDHE-RSA-AES128-GCM-SHA256:HIGH:!aNULL:!MD5:!RC4:!DHE;
ssl_prefer_server_ciphers on;
# The domain name of the first project ( First level domain name )
server_name www.chenzhanxu.top;
charset UTF-8;
# Error log
access_log /home/ubuntu/chenzhanxu/blog/log/blog_access.log;
error_log /home/ubuntu/chenzhanxu/blog/log/blog_error.log;
client_max_body_size 75M;
location / {
include uwsgi_params;
uwsgi_pass 127.0.0.1:8001; # Port number - Want to be with uwsgi The same as in China
uwsgi_read_timeout 10;
}
# Static files
location /static {
expires 30d;
autoindex on;
add_header Cache-Control private;
alias /home/ubuntu/chenzhanxu/blog/app/static;
}
}
# The second project configuration
server {
listen 80 default_server;
# The domain name of the second project ( Two level domain name )
server_name resume.chenzhanxu.top;
charset UTF-8;
# Error log
access_log /home/ubuntu/chenzhanxu/resume/log/resume_access.log;
error_log /home/ubuntu/chenzhanxu/resume/log/resume_error.log;
client_max_body_size 75M;
client_header_buffer_size 16k;
large_client_header_buffers 4 64k;
location / {
include uwsgi_params;
uwsgi_pass 127.0.0.1:8000; # Port number - Want to be with uwsgi The same as in China
uwsgi_read_timeout 10;
}
# Static files
location /static {
expires 30d;
autoindex on;
add_header Cache-Control private;
alias /home/ubuntu/chenzhanxu/resume/app/static;
}
}

Nginx And uwsgi Once the configuration is complete , use uwsgi Start project . 

# You need to run on the following directory of the project uwsgi.ini file
sudo uwsgi --ini uwsgi.ini
# Background operation , close ssh You can also view
sudo uwsgi -d --ini uwsgi.ini
# View the running uwsgi
ps -ef|grep uwsgi
# Turn off running uwsgi
udo kill -9 *****

版权声明:本文为[Empire my love]所创,转载请带上原文链接,感谢。 https://pythonmana.com/2022/134/202205141446234607.html