- 一、安装python
- 二、安装mysql
- 三、安装nginx
https://www.jianshu.com/p/a679b602ef24
-
四、安装git
-
五、开始部署项目
安装 uwsgi
1、 pip3 install uwsgi
2、在django项目下新建myuwsgi.ini文件 (文件名可自取)
# myannounce_uwsgi.ini file
[uwsgi]
# Django-related settings
socket = :8004 #服务端口号
# the base directory (full path)
chdir = /home/hc/my_project #服务器项目路径
home = /home/hc/ENV/ #服务器虚拟环境路径
PYTHONHOME = /home/hc/ENV/
# Django s wsgi file
module = announce.wsgi
# process-related settings
# master
master = true
# maximum number of worker processes
processes = 4
buffer-size = 65536
# ... with appropriate permissions - may be needed
# chmod-socket = 664
# clear environment on exit
vacuum = true
3、进入项目根目录执行:
uwsgi --ini myuwsgi.ini
[uWSGI] getting INI configuration from myannounce_uwsgi.ini
*** Starting uWSGI 2.0.20 (64bit) on [Mon Dec 13 15:32:12 2021] ***
compiled with version: 4.8.5 20150623 (Red Hat 4.8.5-44) on 13 December 2021 07:15:39
os: Linux-3.10.0-1160.11.1.el7.x86_64 #1 SMP Fri Dec 18 16:34:56 UTC 2020
nodename: VM-20-3-centos
machine: x86_64
clock source: unix
pcre jit disabled
detected number of CPU cores: 2
current working directory: /home/hc/my_project
detected binary path: /home/hc/ENV/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 /home/hc/my_project
your processes number limit is 15066
your memory page size is 4096 bytes
detected max file descriptor number: 100001
lock engine: pthread robust mutexes
thunder lock: disabled (you can enable it with --thunder-lock)
uwsgi socket 0 bound to TCP address :8808 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.8.10 (default, Dec 8 2021, 10:12:45) [GCC 4.8.5 20150623 (Red Hat 4.8.5-44)]
PEP 405 virtualenv detected: /home/hc/ENV/
Set PythonHome to /home/hc/ENV/
*** Python threads support is disabled. You can enable it with --enable-threads ***
Python main interpreter initialized at 0xf1ad30
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 671795 bytes (656 KB) for 4 cores
*** Operational MODE: preforking ***
WSGI app 0 (mountpoint='') ready in 0 seconds on interpreter 0xf1ad30 pid: 17529 (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: 17529)
spawned uWSGI worker 1 (pid: 17531, cores: 1)
spawned uWSGI worker 2 (pid: 17532, cores: 1)
spawned uWSGI worker 3 (pid: 17533, cores: 1)
spawned uWSGI worker 4 (pid: 17534, cores: 1)
没有报错则启动成功
4、配置nginx
在nginx 同级目录下创建 nginx.conf -> my.conf文件
server {
listen 8809; # 修改端口号
server_name localhost;
root /home/hc/my_project/front/dist; #前端vue项目
index index.html;
try_files $uri $uri/ /index.html;
#charset koi8-r;
#access_log logs/host.access.log main;
location /api/{
include uwsgi_params; # 通过uwsgi转发请求
uwsgi_pass 127.0.0.1:8004; # 和上文配置的socket端口保持一致
uwsgi_read_timeout 15;
}
location /statics{
expires 30d;
autoindex off; #关闭对目录的访问
add_header Cache-Control private;
alias /home/hc/my_project/myproject_app/static;
}
location ~.*\.sql { #禁止sql文件被访问
deny all;
}
}
进入 nginx.conf 配置
#user nobody;
worker_processes 1;
#error_log logs/error.log;
#error_log logs/error.log notice;
#error_log logs/error.log info;
#pid logs/nginx.pid;
events {
worker_connections 1024;
}
http {
client_max_body_size 8M;#(配置请求体缓存区大小,)
client_body_buffer_size 128k;#(设置客户端请求体最大值)
fastcgi_intercept_errors on;
include mime.types;
default_type application/octet-stream;
#log_format main '$remote_addr - $remote_user [$time_local] "$request" '
# '$status $body_bytes_sent "$http_referer" '
# '"$http_user_agent" "$http_x_forwarded_for"';
#access_log logs/access.log main;
sendfile on;
#tcp_nopush on;
#keepalive_timeout 0;
keepalive_timeout 65;
include /usr/local/nginx/conf/conf.d/*.conf;
#gzip on;
server {
listen 80;
server_name localhost;
#charset koi8-r;
#access_log logs/host.access.log main;
location / {
root html;
index index.html index.htm;
}
#error_page 404 /404.html;
# redirect server error pages to the static page /50x.html
#
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
# proxy the PHP scripts to Apache listening on 127.0.0.1:80
#
#location ~ \.php$ {
# proxy_pass http://127.0.0.1;
#}
# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
#
#location ~ \.php$ {
# root html;
# fastcgi_pass 127.0.0.1:9000;
# fastcgi_index index.php;
# fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name;
# include fastcgi_params;
#}
# deny access to .htaccess files, if Apache's document root
# concurs with nginx's one
#
#location ~ /\.ht {
# deny all;
#}
}
# another virtual host using mix of IP-, name-, and port-based configuration
#
#server {
# listen 8000;
# listen somename:8080;
# server_name somename alias another.alias;
# location / {
# root html;
# index index.html index.htm;
# }
#}
# HTTPS server
}
重启 nginx -s reload
网友评论