nginx部署项目
发布日期:2021-10-25 13:14:37 浏览次数:2 分类:技术文章

本文共 6197 字,大约阅读时间需要 20 分钟。

一.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 install
1)解压nginx
[root@db01 ~]# tar xf nginx-1.10.3.tar.gz
2)进入nginx目录,并查看
[root@db01 ~]# cd nginx-1.10.3

[root@db01 nginx-1.10.3]# ll

total 672
drwxr-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.ru
drwxr-xr-x. 2 1001 1001 168 May 13 09:04 conf
-rwxr-xr-x. 1 1001 1001 2481 Jan 31 2017 configure
drwxr-xr-x. 4 1001 1001 72 May 13 09:04 contrib
drwxr-xr-x. 2 1001 1001 40 May 13 09:04 html
-rw-r--r--. 1 1001 1001 1397 Jan 31 2017 LICENSE
drwxr-xr-x. 2 1001 1001 21 May 13 09:04 man
-rw-r--r--. 1 1001 1001 49 Jan 31 2017 README
drwxr-xr-x. 9 1001 1001 91 May 13 09:04 src

3)创建nginx用户

[root@db01 nginx-1.10.3]# useradd nginx -s /sbin/nologin -M

4)生成make file

./configure \
--user=nginx \
--group=nginx \
--prefix=/usr/local/nginx-1.10.3/ \
--with-http_stub_status_module \
--with-http_ssl_module --with-stream

5)编译 && 安装

[root@db01 nginx-1.10.3]# make && make install

6)做软连接

[root@db01 ~]# ln -s /usr/local/nginx-1.10.3 /usr/local/nginx

[root@db01 ~]# ll /usr/local/nginx/

total 4
drwxr-xr-x. 2 root root 4096 May 13 09:13 conf
drwxr-xr-x. 2 root root 40 May 13 09:13 html
drwxr-xr-x. 2 root root 6 May 13 09:13 logs
drwxr-xr-x. 2 root root 19 May 13 09:13

7)检测nginx语法
[root@db01 conf]# /usr/local/nginx/sbin/nginx -t
nginx: the configuration file /usr/local/nginx-1.10.3//conf/nginx.conf syntax is ok
nginx: 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 80
tcp 0 0 0.0.0.0:80 0.0.0.0:* LISTEN 61777/nginx: master

10)重新加载

[root@db01 conf]# /usr/local/nginx/sbin/nginx -s reload

11)简化nginx配置文件

[root@db01 conf]# grep -Ev "#|^$" nginx.conf.default > nginx.conf

12)创建conf.d目录

[root@db01 conf]# mkdir /usr/local/nginx/conf/conf.d

13)编辑虚拟主机

[root@db01 conf.d]# vim www.oldboy.com.conf
server {
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 /code

15)上传代码

16)重新加载nginx

[root@db01 code]# /usr/local/nginx/sbin/nginx -t
nginx: the configuration file /usr/local/nginx-1.10.3//conf/nginx.conf syntax is ok
nginx: 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.gz

2)解压

[root@db01 opt]# tar xf node-v8.6.0-linux-x64.tar.gz

3)移动目录

[root@db01 opt]# mv node-v8.6.0-linux-x64 /usr/local/node-8.6.0

4)做软连接

ln -s /usr/local/node-8.6.0 /usr/local/node

5)进入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 node
lrwxrwxrwx. 1 500 500 38 Sep 27 2017 npm -> ../lib/node_modules/npm/bin/npm-cli.js
lrwxrwxrwx. 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.sh
export PATH="/usr/local/node/bin:$PATH"

7)加载环境变量

[root@db01 node]# source /etc/profile

8)检测node和npm版本

[root@db01 node]# npm -v
5.3.0
[root@db01 node]# node -v
v8.6.0

9)解压vue代码
[root@db01 opt]# unzip 07-luffy_project_01.zip

10)进入代码目录,安装package.json中的模块

[root@db01 opt]# cd 07-luffy_project_01
[root@db01 07-luffy_project_01]# npm install

11)更改js文件中的IP

sed -i 's#127.0.0.1#10.0.0.51#g' /opt/07-luffy_project_01/src/restful/api.js

12)生成静态文件目录

npm run build

13)编辑 nginx配置文件,创建一个虚拟主机

[root@db01 dist]# vim /usr/local/nginx/conf/conf.d/www.luffy.com.conf

server {

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.com

15)重新加载nginx

[root@db01 dist]# /usr/local/nginx/sbin/nginx -t
nginx: the configuration file /usr/local/nginx-1.10.3//conf/nginx.conf syntax is ok
nginx: 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.tgz

2)解压

[root@db01 ~]# tar xf Python-3.6.4.tgz

3)进入python3目录

[root@db01 ~]# cd Python-3.6.4

4)生成make file

./configure --prefix=/usr/local/python3.6.4 --with-ssl

5)编译 && 安装

[root@db01 Python-3.6.4]# make && make install

6)编辑python需要安装的库文件
[root@db01 opt]# vim requirements.txt
certifi==2018.11.29
chardet==3.0.4
crypto==1.4.1
Django==2.1.4
django-redis==4.10.0
django-rest-framework==0.1.0
djangorestframework==3.9.0
idna==2.8
Naked==0.1.31
pycrypto==2.6.1
pytz==2018.7
PyYAML==3.13
redis==3.0.1
requests==2.21.0
shellescape==3.4.1
urllib3==1.24.1
uWSGI==2.0.17.1

7)安装库文件

[root@db01 opt]# pip3 install -r requirements.txt

8)解压后端代码

[root@db01 opt]# unzip luffy_boy.zip

9)编辑uwsgi文件

[root@db01 opt]# vim /opt/uwsgi.ini
[uwsgi]
# Django-related settings
# the base directory (full path)
chdir = /opt/luffy_boy
# Django's wsgi file
module = boy.wsgi
# the virtualenv (full path)
home = /usr/local/python3.6.4
# process-related settings
# master
master = true
# maximum number of worker processes
processes = 100
# the socket (use the full path to be safe
socket = 0.0.0.0:8888
# clear environment on exit
vacuum = 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

 

转载于:https://www.cnblogs.com/wrqysrt/p/10858881.html

转载地址:https://blog.csdn.net/weixin_30909575/article/details/99061320 如侵犯您的版权,请留言回复原文章的地址,我们会给您删除此文章,给您带来不便请您谅解!

上一篇:volatile可见性的一些认识和论证
下一篇:IIS7/IIS7.5 二级域名伪静态设置方法

发表评论

最新留言

第一次来,支持一个
[***.219.124.196]2024年03月26日 11时54分49秒

关于作者

    喝酒易醉,品茶养心,人生如梦,品茶悟道,何以解忧?唯有杜康!
-- 愿君每日到此一游!

推荐文章

24v开关电源维修技巧_【电视技术】液晶电视电源板十个维修经验分享 2019-04-21
laravel comment显示到页面最上面了_使用 Laravel 快速开发API接口,新手必读 2019-04-21
echart实现3d地图_orbslam_2生成稀疏点云地图的保存与加载的实现 邹鹏程 2019.9.15... 2019-04-21
bash 不是内部或外部命令_python学习笔记6-pip命令不是内部命令问题 2019-04-21
管道的另一端上无任何进程。_别被忽悠入坑!信号贴贴上就能信号满格?对手机信号无任何改善... 2019-04-21
mysql无法写数据库_求助,为何我的数据不能写入数据库 2019-04-21
ssh 两个mysql数据库_ssh连接两个数据库(转) 2019-04-21
mysql 双向链表_23张图!万字详解「链表」,从小白到大佬! 2019-04-21
mysql 常量命名规则_详解Java编程规约(命名风格、常量定义、代码格式) 2019-04-21
pomelo mysql_全文索引 - Pomelo.EFCore.MySql 2019-04-21
如何打开git命令窗口_win10系统如何将右键菜单中“在此处打开powershell窗口”调整为“在此处打开命令窗口”?... 2019-04-21
rtsp 华为_华为多实例生成树RSTP配置详解 2019-04-21
ewb交通灯报告和文件_基于ewb平台的交通灯电路设计.doc 2019-04-21
mysql中$使用_在MySQL中使用序列的简单教程 2019-04-21
mysql alter auto increment_将MySQL列更改为AUTO_INCREMENT 2019-04-21
mysql+err+1067_MySQL 5.7 Invalid default value for 'CREATE_TIME'报错的解决方法 2019-04-21
程序中mysql添加用户_MySQL添加用户的两种方法 2019-04-21
简述mysql安装过程_mysql安装的过程 2019-04-21
后端接口重定向_不用再等后端的接口啦!这个开源项目花 2 分钟就能模拟出后端接口... 2019-04-21
学mysql需要英语水平多高_大学英语专业挂科率高吗 2019-04-21