nginx环境搭建

1.官网下载

  • cd /usr/local
  • wget http://nginx.org/download/nginx-1.24.0.tar.gz
  • 没有wget,就手动下载传上去

2.解压

  • tar -zxvf nginx-1.24.0.tar.gz

3.进行configure配置

cd nginx-1.24.0
./configure --prefix=/usr/local/nginx --with-http_ssl_module --with-http_flv_module --with-http_stub_status_module --with-http_gzip_static_module --with-http_realip_module --with-pcre --with-stream

查看是否报错

4.上面报错就下载所需要的依赖库文件

  • yum install -y gcc
checking for OS
 + Linux 3.10.0-1160.el7.x86_64 x86_64
checking for C compiler ... not found

./configure: error: C compiler cc is not found
  • yum install -y pcre-devel
./configure: error: the HTTP rewrite module requires the PCRE library.
You can either disable the module by using --without-http_rewrite_module
option, or install the PCRE library into the system, or build the PCRE library
statically from the source with nginx by using --with-pcre=<path> option.
  • yum install -y zlib-devel
./configure: error: the HTTP gzip module requires the zlib library.
You can either disable the module by using --without-http_gzip_module
option, or install the zlib library into the system, or build the zlib library
statically from the source with nginx by using --with-zlib=<path> option.

如果还有其他错误安装下面依赖或者百度下

  • yum install pcre
  • yum install zlib
  • yum -y install make zlib-devel gcc-c++ libtool openssl openssl-devel

5.编译安装

make && make install

(注意如果不添加上面的所依赖库会报错)

6.启动Nginx

下面二选一方式启动

个人学习启动步骤

进入安装好的目录的sbin下/usr/local/nginx/sbin,输入 ./nginx 即可启动完成

公司项目经理给的步骤,看需不需要使用
  • 首次启动或者新增了模块(比如原先没有stream模块,现在重新加了之后)需要指定配置文件启动以生效配置文件/usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf
  • cd /usr/local/nginx/目录下:看到如下四个目录
  • conf配置文件 html网页文件 logs日志文件 sbin主要二进制程序
  • 启动命令:/usr/local/nginx/sbin/nginx -s stop 关闭, /usr/local/nginx/sbin/nginx -s reload 重启

7.查看是否启动成功

  • 成功:查看是否启动(netstat -ano|grep 80) 失败:可能为80端口被占用,或者防火墙没放行等。
  • 浏览器访问地址:http://服务器ip(看到欢迎界面即可)
  • 在这里插入图片描述

8.设置开机启动

创建服务脚本

vi /usr/lib/systemd/system/nginx.service

服务脚本内容

[Unit]
Description=nginx - web server
After=network.target remote-fs.target nss-lookup.target
[Service]
Type=forking
PIDFile=/usr/local/nginx/logs/nginx.pid
ExecStartPre=/usr/local/nginx/sbin/nginx -t -c /usr/local/nginx/conf/nginx.conf
ExecStart=/usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf
ExecReload=/usr/local/nginx/sbin/nginx -s reload
ExecStop=/usr/local/nginx/sbin/nginx -s stop
ExecQuit=/usr/local/nginx/sbin/nginx -s quit
PrivateTmp=true
[Install]
WantedBy=multi-user.target

重新加载系统服务

systemctl daemon-reload

启动服务

systemctl start nginx.service

开机启动

systemctl enable nginx.service

重启下,在访问ip,能访问得到就是可以了

新增模块,使其生效

依旧是执行以下语句,进入nginx源文件目录,重新配置

cd nginx-1.24.0
./configure --prefix=/usr/local/nginx --with-http_ssl_module --with-http_flv_module --with-http_stub_status_module --with-http_gzip_static_module --with-http_realip_module --with-pcre --with-stream

接着编译安装,看到文章说不用 make install,到时候出问题在执行make install下

make

杀死nginx相关进程,然后重新运行加载配置即可

/usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值