美文网首页
nginx-1.16.1编译安装

nginx-1.16.1编译安装

作者: 冰岛星 | 来源:发表于2020-05-15 16:44 被阅读0次

nginx 源码包下载地址:
http://nginx.org/en/download.html

1)下载依赖库:
 [root@localhost ~]# yum install gcc gcc-c++ automake pcre pcre-devel zlip zlib-devel openssl openssl-devel   
2) 创建nginx用户
[root@localhost sbin]# useradd -s /sbin/nologin -M nginx  #否则会出现问题1
3)解压nginx:
 [root@localhost ~]# mkdir /downloads
[root@localhost ~]# cd /downloads/
[root@localhost download]# tar -xzf nginx-1.16.1.tar.gz -C /usr/local/
4) 编译安装
[root@localhost local]# cd /usr/local/
[root@localhost local]# mkdir -p /usr/local/nginx  /var/tmp/nginx/client/
[root@localhost nginx-1.16.1]# ./configure  --prefix=/usr/local/nginx  --sbin-path=/usr/local/nginx/sbin/nginx --conf-path=/usr/local/nginx/conf/nginx.conf --error-log-path=/var/log/nginx/error.log  --http-log-path=/var/log/nginx/access.log  --pid-path=/var/run/nginx/nginx.pid --lock-path=/var/lock/nginx.lock  --user=nginx --group=nginx --with-http_ssl_module --with-http_stub_status_module --with-http_gzip_static_module --http-client-body-temp-path=/var/tmp/nginx/client/ --http-proxy-temp-path=/var/tmp/nginx/proxy/ --http-fastcgi-temp-path=/var/tmp/nginx/fcgi/ --http-uwsgi-temp-path=/var/tmp/nginx/uwsgi --http-scgi-temp-path=/var/tmp/nginx/scgi --with-pcre
[root@localhost nginx-1.16.1]# make 
[root@localhost nginx-1.16.1]# make install
5)启动nginx:
[root@localhost sbin]# /usr/local/nginx/sbin/nginx -t  #检查配置文件语法问题
显示结果如下为成功:
nginx: the configuration file /usr/local/nginx/conf/nginx.conf syntax is ok
nginx: configuration file /usr/local/nginx/conf/nginx.conf test is successful
[root@localhost sbin]# /usr/local/nginx/sbin/nginx  #启动nginx,可能会出现问题2,/var/run/nginx/nginx.pid找不到的问题
6) 添加环境变量
[root@localhost init.d]# vim /etc/profile
export PATH=$PATH:/usr/local/nginx/sbin
[root@localhost init.d]# source /etc/profile
7)查看端口80:
[root@localhost sbin]# ss -lntp
8)nginx的相关动作:
nginx -s reload          重新载入配置文件
nginx -s reopen         重启 Nginx
nginx -s stop             快速关闭 Nginx
nginx -s quit              关闭Nginx

扩展1:若想用systemctl启动方式启动nginx服务,可以进行如下修改:
[root@localhost sbin]# vim  /usr/lib/systemd/system/nginx.service
添加如下内容:
[Unit]
Description=nginx
After=network.target remote-fs.target nss-lookup.target
[Service]
Type=forking
PIDFile=/run/nginx.pid
ExecStartPre=/usr/bin/rm -f /run/nginx.pid
ExecStartPre=/usr/sbin/nginx -t
ExecStart=/usr/sbin/nginx
ExecReload=/bin/kill -s HUP $MAINPID
KillMode=process
KillSignal=SIGQUIT
TimeoutStopSec=5
PrivateTmp=true
[Install]
WantedBy=multi-user.target
[root@localhost sbin]#  systemctl daemon-reload #重新加载配置文件,便可进行systemctl命令使用

问题1:
由于没有nginx用户,会出现如下问题:


image.png

解决方法:
[root@localhost sbin]# useradd -s /sbin/nologin -M nginx

问题2:
/var/run/nginx/nginx.pid文件打不开


image.png

解决方法:
[root@localhost nginx]# cd /usr/local/nginx/conf/
[root@localhost conf]# vim nginx.conf
将原来的#pid logs/nginx.pid; 去掉注释
并改为:pid /usr/local/nginx/nginx.pid;
再次启动就可以了

实验结果显示:


image.png
image.png

访问ip可得:

image.png

相关文章

  • nginx-1.16.1编译安装

    nginx 源码包下载地址:http://nginx.org/en/download.html 问题1:由于没有n...

  • 搭建并配置LAMP/LNMP环境

    如何编译安装软件编译安装是Linux安装软件的重要方式编译前的准备工作:./configure编译:make安装:...

  • Linux下编译Xmrig

    安装依赖 Ubuntu CentOS 安装 创建编译文件夹 编译安装 基本编译方式 静态编译方式 编译完成后使用l...

  • php 手动编译添加扩展

    在完成 php的编译安装后, 发现没有编译某此模块。手动添加安装。php源码编译安装 编译安装 在php源码包中 ...

  • 编译安装LNMP

    编译安装nginx 编译安装PHP 配置Nginx+PHP 安装MySQL

  • 编译安装LNMP2

    编译安装nginx 编译安装PHP 配置Nginx+PHP 安装MySQL

  • Centos7 安装Nginx

    一、编译安装 1、安装编译安装所需要的依赖 2、下载Nginx 3、解压 4、编译安装(默认设置) 5、查看安装目...

  • Hbuilder scss/sass编译 插件

    1. 安装插件 工具 -> 插件安装 -> scss/sass编译 -> 安装安装 scss/sass编译 插件 ...

  • nginx+passenger配置rails的生产环境

    先编译方式安装好nginx ==> 安装教程 安装passenger 编译安装,只需要在原来的编译配置参数后补上就...

  • nginx 编译安装支持 ssl

    nginx 编译安装支持 ssl [toc] 标签(空格分隔): nginx 安装编译环境和必要的库 编译安装pc...

网友评论

      本文标题:nginx-1.16.1编译安装

      本文链接:https://www.haomeiwen.com/subject/nbvcohtx.html