一.nginx的作用:
1.做静态页展示的web服务
2.nginx做负载均衡 四层 七层3.反向代理yum install -y pcre-devel autoconf openssl-devel
注意:nginx 不可以直接连接数据库,在nginx1.9.x 之前,不支持四层负载,stream模块.
二.源码安装nginx
1)解压
2)生成 (make file)cmake ./configure --prefix=/usr/local/nginx 3)编译 make 4)安装 make install1)解压nginx[root@db01 ~]# tar xf nginx-1.10.3.tar.gz2)进入nginx目录,并查看[root@db01 ~]# cd nginx-1.10.3[root@db01 nginx-1.10.3]# ll
total 672drwxr-xr-x. 6 1001 1001 4096 May 13 09:04 auto-rw-r--r--. 1 1001 1001 265299 Jan 31 2017 CHANGES-rw-r--r--. 1 1001 1001 404694 Jan 31 2017 CHANGES.rudrwxr-xr-x. 2 1001 1001 168 May 13 09:04 conf-rwxr-xr-x. 1 1001 1001 2481 Jan 31 2017 configuredrwxr-xr-x. 4 1001 1001 72 May 13 09:04 contribdrwxr-xr-x. 2 1001 1001 40 May 13 09:04 html-rw-r--r--. 1 1001 1001 1397 Jan 31 2017 LICENSEdrwxr-xr-x. 2 1001 1001 21 May 13 09:04 man-rw-r--r--. 1 1001 1001 49 Jan 31 2017 READMEdrwxr-xr-x. 9 1001 1001 91 May 13 09:04 src3)创建nginx用户
[root@db01 nginx-1.10.3]# useradd nginx -s /sbin/nologin -M4)生成make file
./configure \--user=nginx \--group=nginx \--prefix=/usr/local/nginx-1.10.3/ \--with-http_stub_status_module \--with-http_ssl_module --with-stream5)编译 && 安装
[root@db01 nginx-1.10.3]# make && make install6)做软连接
[root@db01 ~]# ln -s /usr/local/nginx-1.10.3 /usr/local/nginx[root@db01 ~]# ll /usr/local/nginx/
total 4drwxr-xr-x. 2 root root 4096 May 13 09:13 confdrwxr-xr-x. 2 root root 40 May 13 09:13 htmldrwxr-xr-x. 2 root root 6 May 13 09:13 logsdrwxr-xr-x. 2 root root 19 May 13 09:13 7)检测nginx语法[root@db01 conf]# /usr/local/nginx/sbin/nginx -tnginx: the configuration file /usr/local/nginx-1.10.3//conf/nginx.conf syntax is oknginx: configuration file /usr/local/nginx-1.10.3//conf/nginx.conf test is successful 8)启动nginx[root@db01 conf]# /usr/local/nginx/sbin/nginx 9)检查nginx的端口[root@db01 conf]# netstat -lntup|grep 80tcp 0 0 0.0.0.0:80 0.0.0.0:* LISTEN 61777/nginx: master10)重新加载
[root@db01 conf]# /usr/local/nginx/sbin/nginx -s reload11)简化nginx配置文件
[root@db01 conf]# grep -Ev "#|^$" nginx.conf.default > nginx.conf12)创建conf.d目录
[root@db01 conf]# mkdir /usr/local/nginx/conf/conf.d13)编辑虚拟主机
[root@db01 conf.d]# vim www.oldboy.com.confserver { listen 80; server_name localhost; location / { 站点目录的根目录位置 root html; =============> root /code/;index index.html index.htm;
} error_page 500 502 503 504 /50x.html; location = /50x.html { root html; }}14)创建站点目录
[root@db01 html]# mkdir /code15)上传代码
16)重新加载nginx
[root@db01 code]# /usr/local/nginx/sbin/nginx -tnginx: the configuration file /usr/local/nginx-1.10.3//conf/nginx.conf syntax is oknginx: configuration file /usr/local/nginx-1.10.3//conf/nginx.conf test is successful[root@db01 code]# /usr/local/nginx/sbin/nginx -s reload什么叫站点目录?
前端代码存放的目录
三.部署VUE
1)下载node
wget https://nodejs.org/download/release/v8.6.0/node-v8.6.0-linux-x64.tar.gz2)解压
[root@db01 opt]# tar xf node-v8.6.0-linux-x64.tar.gz3)移动目录
[root@db01 opt]# mv node-v8.6.0-linux-x64 /usr/local/node-8.6.04)做软连接
ln -s /usr/local/node-8.6.0 /usr/local/node5)进入node目录,查看bin目录
[root@db01 opt]# cd /usr/local/node[root@db01 node]# ll bin/total 36264-rwxrwxr-x. 1 500 500 37133148 Sep 27 2017 nodelrwxrwxrwx. 1 500 500 38 Sep 27 2017 npm -> ../lib/node_modules/npm/bin/npm-cli.jslrwxrwxrwx. 1 500 500 38 Sep 27 2017 npx -> ../lib/node_modules/npm/bin/npx-cli.js 6)添加环境变量[root@db01 node]# vim /etc/profile.d/node.shexport PATH="/usr/local/node/bin:$PATH"7)加载环境变量
[root@db01 node]# source /etc/profile8)检测node和npm版本
[root@db01 node]# npm -v5.3.0[root@db01 node]# node -vv8.6.0 9)解压vue代码[root@db01 opt]# unzip 07-luffy_project_01.zip10)进入代码目录,安装package.json中的模块
[root@db01 opt]# cd 07-luffy_project_01[root@db01 07-luffy_project_01]# npm install11)更改js文件中的IP
sed -i 's#127.0.0.1#10.0.0.51#g' /opt/07-luffy_project_01/src/restful/api.js12)生成静态文件目录
npm run build13)编辑 nginx配置文件,创建一个虚拟主机
[root@db01 dist]# vim /usr/local/nginx/conf/conf.d/www.luffy.com.confserver {
listen 80; server_name www.luffy.com; location / { root /opt/07-luffy_project_01/dist; index index.html index.htm; } error_page 400 403 404 405 /40x.html;}14)配置hosts解析
10.0.0.51 www.luffy.com15)重新加载nginx
[root@db01 dist]# /usr/local/nginx/sbin/nginx -tnginx: the configuration file /usr/local/nginx-1.10.3//conf/nginx.conf syntax is oknginx: configuration file /usr/local/nginx-1.10.3//conf/nginx.conf test is successful[root@db01 dist]# /usr/local/nginx/sbin/nginx -s reload 四.源码安装python3.6环境1)下载[root@db01 ~]# wget https://www.python.org/ftp/python/3.6.4/Python-3.6.4.tgz2)解压
[root@db01 ~]# tar xf Python-3.6.4.tgz3)进入python3目录
[root@db01 ~]# cd Python-3.6.44)生成make file
./configure --prefix=/usr/local/python3.6.4 --with-ssl5)编译 && 安装
[root@db01 Python-3.6.4]# make && make install 6)编辑python需要安装的库文件[root@db01 opt]# vim requirements.txtcertifi==2018.11.29chardet==3.0.4crypto==1.4.1Django==2.1.4django-redis==4.10.0django-rest-framework==0.1.0djangorestframework==3.9.0idna==2.8Naked==0.1.31pycrypto==2.6.1pytz==2018.7PyYAML==3.13redis==3.0.1requests==2.21.0shellescape==3.4.1urllib3==1.24.1uWSGI==2.0.17.17)安装库文件
[root@db01 opt]# pip3 install -r requirements.txt8)解压后端代码
[root@db01 opt]# unzip luffy_boy.zip9)编辑uwsgi文件
[root@db01 opt]# vim /opt/uwsgi.ini [uwsgi]# Django-related settings# the base directory (full path)chdir = /opt/luffy_boy# Django's wsgi filemodule = boy.wsgi# the virtualenv (full path)home = /usr/local/python3.6.4# process-related settings# mastermaster = true# maximum number of worker processesprocesses = 100# the socket (use the full path to be safesocket = 0.0.0.0:8888# clear environment on exitvacuum = true
可能需要虚拟环境配置,然后环境变量加上一些python包的路径
根据公网ip配置nginx的文件,与前端配置i相似
server {
listen 80; server_name 106.14.188.4; location / { root /code/video_vue/dist; } location /media { include uwsgi_params; uwsgi_pass 106.14.188.4:8000; } location /video { include uwsgi_params; uwsgi_pass 106.14.188.4:8000; } error_page 400 403 404 405 /index.html;}
修改前端url请求地址与后端地址一致
10)启动uwsgi
[root@db01 opt]# uwsgi --ini /opt/uwsgi.ini &前面加nohup切断连接中断信号的发送
绝对路径:/usr/local/python3.6.4/bin/uwsgi --ini /opt/uwsgi.ini & 检测是否启动成功:打开浏览器,访问:10.0.0.51:8888