第一次在CSDN上面写博客,闲话休说、言归正传。
手上有个项目是vue+django的模式,需求是vue部署到一台服务器上,django部署到另外一台服务器上
第一步:安装nginx.......怎么安装请谷歌,在此不做赘述(有很多类似的教程)
第二步:找到nginx的配置文件:/etc/nginx/nginx.conf #路径可能不一定是这个,根据实际情况而定
部署vue+nginx
代码如下:
http {
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 /var/log/nginx/access.log main;
sendfile on;
tcp_nopush on;
tcp_nodelay on;
keepalive_timeout 65;
types_hash_max_size 2048;
include /etc/nginx/mime.types;
default_type application/octet-stream;
# Load modular configuration files from the /etc/nginx/conf.d directory.
# See http://nginx.org/en/docs/ngx_core_module.html#include
# for more information.
include /etc/nginx/conf.d/*.conf;
server {
#外部访问的端口(必须)
listen 80;
#服务器名称,随便写
server_name testproject;
location / {
root /test/testproject/dist; #该路径是vue build后的dist的路径
index index.html; #照抄
}
location /api { #vue里面的后台api地址,这里也需要设置下
proxy_pass http://服务器IP:端口/;
}
error_page 404 /404.html;
location = /40x.html {
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
}
}
核心设置部分就是红色框框里面的内容
重启nginx就OK了
第三步:linux+uwsgi+nginx部署
另外一台服务器,安装nginx,然后安装uwsgi,uwsgi.ini配置如下:
[uwsgi]
socket=127.0.0.1:8000
chdir=/testprojectapi/test #项目目录
wsgi-file=test/wsgi.py #项目目录wsgi.py文件的相对路径
processes=2
threads=1
master=True
pidfile=uwsgi.pid
daemonize=uwsgi.log
启动uwsgi:uwsgi --ini uwsgi.ini
nginx配置如下:
server {
listen 9009; #外部访问的端口
server_name testproject;
location / {
include uwsgi_params;
uwsgi_pass 127.0.0.1:8000; #uwsgi配置的端口
client_max_body_size 35m;
}
location /static {
alias /test/testproject/static; #静态文件存放的地址
}
}
重启nginx,完成