服务器部署Nginx

1.环境准备

# 安装gcc  个命令将会安装一系列软件包,包括gcc,c++,和make
apt install build-essential
# 检查gcc版本 
gcc --version

#  安装 pcre 
apt-get install libpcre3 libpcre3-dev
# 安装通讯依赖    这个应该是自带的有,但是不装又会报错,哈哈
apt-get install openssl libssl-dev

以下是执行 gcc --version 指令看到的情况

2-1.把 nginx 的源码包nginx-1.8.0.tar.gz上传到 linux 系统

提取码:ngix

2-2.解压安装包

# 解压Nginx
tar -zxvf nginx-1.8.0.tar.gz
# 给Nginx改名
mv  nginx-1.8.0  nginx
# 进入Nginx
cd  nginx

# 将zlib下载到当前目录=====这个操作可以提前做,不一定要在这里操作  
wget http://www.zlib.net/zlib-1.2.11.tar.gz
# 解压 zlib
tar -zxvf zlib-1.2.11.tar.gz
# 进入 zlib
cd zlib-1.2.11
# 执行 zlib 配置
./configure
# 编译
make
# 编译安装
make install

2-3.进入nginx目录 使用 configure 命令创建 makeFile 文件。

 ./configure \
--prefix=/usr/local/nginx \
--pid-path=/var/run/nginx/nginx.pid \
--lock-path=/var/lock/nginx.lock \
--error-log-path=/var/log/nginx/error.log \
--http-log-path=/var/log/nginx/access.log \
--with-http_gzip_static_module \
--http-client-body-temp-path=/var/temp/nginx/client \
--http-proxy-temp-path=/var/temp/nginx/proxy \
--http-fastcgi-temp-path=/var/temp/nginx/fastcgi \
--http-uwsgi-temp-path=/var/temp/nginx/uwsgi \
--http-scgi-temp-path=/var/temp/nginx/scgi

补充知识 无需运行 

./configure \
--prefix=/usr/local/nginx \                                                 #指向安装目录
--sbin-path=/usr/sbin/nginx \                                 #指向(执行)程序文件(nginx)
--conf-path=/etc/nginx/nginx.conf \                      #指向配置文件
--error-log-path=/var/log/nginx/error.log \              #指向log
--http-log-path=/var/log/nginx/access.log \            #指向http-log
--pid-path=/var/run/nginx/nginx.pid \                      #指向pid
--lock-path=/var/lock/nginx.lock \                         #(安装文件锁定,防止安装文件被别人利用,或自己误操作。)
--user=nginx \
--group=nginx \
--with-http_ssl_module \                      #启用ngx_http_ssl_module支持(使支持https请求,需已安装openssl)
--with-http_flv_module \                       #启用ngx_http_flv_module支持(提供寻求内存使用基于时间的偏移量文件)
--with-http_stub_status_module \               #启用ngx_http_stub_status_module支持(获取nginx自上次启动以来的工作状态)
--with-http_gzip_static_module \              #启用ngx_http_gzip_static_module支持(在线实时压缩输出数据流)
--http-client-body-temp-path=/var/tmp/nginx/client/ \           #设定http客户端请求临时文件路径
--http-proxy-temp-path=/var/tmp/nginx/proxy/ \     #设定http代理临时文件路径
--http-fastcgi-temp-path=/var/tmp/nginx/fcgi/ \    #设定http fastcgi临时文件路径
--http-uwsgi-temp-path=/var/tmp/nginx/uwsgi \       #设定http uwsgi临时文件路径
--http-scgi-temp-path=/var/tmp/nginx/scgi \ #设定http scgi临时文件路径
--with-pcre                                 #启用pcre库

如果这里报错,只需要升级 apt-get即可

执行后可以看到Makefile文件  

Makefile是一种配置文件, Makefile 一个工程中的源文件不计数,其按类型、功能、模块分别放在若干个目录中,makefile定义了一系列的规则来指定,哪些文件需要先编译,哪些文件需要后编译,哪些文件需要重新编译,甚至于进行更复杂的功能操作,因为 makefile就像一个Shell脚本一样,其中也可以执行操作系统的命令。

更改/opt/nginx/objs/MakeFile文件  

# 进入 /opt/nginx/objs/ 目录
cd /opt/nginx/objs
# 编辑 Makefile 文件
vim  Makefile
# 修改完毕后保存并退出

 

 更改ngx_user.c文件

# 在 /opt/nginx 目录下 执行编译安装命令  但是此时会报错,报错没关系,就按下图配置
 make && make install

# 在 /opt/nginx 目录下 编辑 ngx_user.c
vim src/os/unix/ngx_user.c
# 命令模式下输入  显示行号的指令
:set number
# 找到 第36行并注释掉

 i进行编辑 编辑完后按ESC :wq 即可退出编辑并保存

 编译安装

 # 在 /opt/nginx 目录下 执行编译安装命令   此时过程中会有报错,但是已经不影响操作
 make && make install

configure参数

./configure \
--prefix=/usr \                                                        #指向安装目录
--sbin-path=/usr/sbin/nginx \                                 #指向(执行)程序文件(nginx)
--conf-path=/etc/nginx/nginx.conf \                      #指向配置文件
--error-log-path=/var/log/nginx/error.log \              #指向log
--http-log-path=/var/log/nginx/access.log \            #指向http-log
--pid-path=/var/run/nginx/nginx.pid \                      #指向pid
--lock-path=/var/lock/nginx.lock \                         #(安装文件锁定,防止安装文件被别人利用,或自己误操作。)
--user=nginx \
--group=nginx \
--with-http_ssl_module \                      #启用ngx_http_ssl_module支持(使支持https请求,需已安装openssl)
--with-http_flv_module \                       #启用ngx_http_flv_module支持(提供寻求内存使用基于时间的偏移量文件)
--with-http_stub_status_module \               #启用ngx_http_stub_status_module支持(获取nginx自上次启动以来的工作状态)
--with-http_gzip_static_module \              #启用ngx_http_gzip_static_module支持(在线实时压缩输出数据流)
--http-client-body-temp-path=/var/tmp/nginx/client/ \           #设定http客户端请求临时文件路径
--http-proxy-temp-path=/var/tmp/nginx/proxy/ \     #设定http代理临时文件路径
--http-fastcgi-temp-path=/var/tmp/nginx/fcgi/ \    #设定http fastcgi临时文件路径
--http-uwsgi-temp-path=/var/tmp/nginx/uwsgi \       #设定http uwsgi临时文件路径
--http-scgi-temp-path=/var/tmp/nginx/scgi \ #设定http scgi临时文件路径
--with-pcre                                 #启用pcre库 

2-4.启动和访问

# 启动nginx 之前,上边将临时文件目录指定为/var/temp/nginx/client, 需要在/var  下创建此 目录
mkdir /var/temp/nginx/client -p
# 进入到Nginx目录下的sbin目录
cd /usr/local/nginx/sbin
# 输入启动命令
./nginx

# 启动后查看进程
ps aux|grep nginx

看到下面的画面即为OK

 测试:使用本机访问虚拟机所在的IP(默认端口80)

猜你喜欢

转载自blog.csdn.net/m0_61157117/article/details/124122869
今日推荐