详细介绍CentOS 源码安装Nginx

目录

 

一、下载Nginx

二、编译Nginx

三、设置Nginx开机自启动


整套的简单安装流程如下,详细的往下看:

mkdir /usr/local/nginx
cd  /usr/local/nginx
wget http://nginx.org/download/nginx-1.16.1.tar.gz
tar -xzvf nginx-1.16.1.tar.gz
cd nginx-1.16.1
mkdir ~/.vim
cp -r contrib/vim/* ~/.vim/
yum -y install gcc gcc-c++ autoconf automake make
yum -y install pcre-devel
yum -y install zlib-devel
yum -y install openssl openssl-devel
./configure --prefix=/usr/local/nginx/compiled
make
make install 

一、下载Nginx

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

1、下载:wget http://nginx.org/download/nginx-1.16.1.tar.gz

2、解压:tar -xzvf nginx-1.16.1.tar.gz

3、复制vim配置文件(使用vim nginx.conf的时候语法高亮显示): cp -r contrib/vim/* ~/.vim/

      没有.vim文件夹的话自己创建一个:mkdir ~/.vim

二、编译Nginx

1、查看编辑支持的参数信息:./configure --help |more

 2、编译nginx(只指定目录):./configure --prefix=/usr/local/nginx/Compiled

 3、编辑报错处理 

             错误信息:/configure: error: C compiler cc is not found
                    执行安装:yum -y install gcc gcc-c++ autoconf automake make

             错误信息:./configure: error: the HTTP rewrite module requires the PCRE library.
                    执行安装:yum -y install pcre-devel

             错误信息:./configure: error: the HTTP gzip module requires the zlib library.
                    执行安装:yum install -y zlib-devel

             错误信息:./configure: error: the HTTP cache module requires md5 functions
                    执行安装:yum -y install openssl openssl-devel

4、查看编译的时候会被加进去的组件列表:cat objs/ngx_modules.c

5、执行编译和安装:

      make

      make install

      nginx的目标文件放置在objs/文件夹下面,如果做nginx的版本升级,不能直接执行make install,还需要从这里将nginx目标文件拷贝的目标安装目录中

6、把防火墙80端口打开:https://blog.csdn.net/qq_26900081/article/details/103922941

三、设置Nginx开机自启动

1、创建文件:vi /lib/systemd/system/nginx.service

2、文件中加入内容如下:

[Unit]
Description=nginx
After=network.target
 
[Service]
Type=forking
#修改以下三个地址为自己的nginx安装地址
ExecStart=/usr/local/nginx/Compiled/sbin/nginx
ExecReload=/usr/local/nginx/Compiled/sbin/nginx -s reload
ExecStop=/usr/local/nginx/Compiled/sbin/nginx -s quit
PrivateTmp=true
 
[Install]
WantedBy=multi-user.target

3、设置开机自启动:systemctl enable nginx

4、其他命令

systemctl enable nginx         设置开机自启动
systemctl disable nginx         停止开机自启动
systemctl start nginx          启动nginx服务
systemctl stop nginx           停止服务
systemctl restart nginx        重新启动服务
systemctl status nginx          查看服务当前状态

 

发布了65 篇原创文章 · 获赞 28 · 访问量 2万+

猜你喜欢

转载自blog.csdn.net/qq_26900081/article/details/103988101
今日推荐