当前位置: 移动技术网 > 网络运营>服务器>nginx > linux下安装Nginx1.16.0的教程详解

linux下安装Nginx1.16.0的教程详解

2019年09月06日  | 移动技术网网络运营  | 我要评论

免费送qq,假发批发市场,王春秋

因为最近在倒腾linux,想安装新版本的nginx,找了一圈教程没有找到对应的教程,在稍微倒腾了一会之后终于成功的安装了最新版。

服务器环境为centos,接下来是详细步骤:

安装必要依赖插件

yum install -y gcc gcc-c++ pcre \
pcre-devel zlib zlib-devel openssl openssl-devel wget

创建文件夹并切换过去

mkdir /customer && cd /customer 

下载安装包 (同样如果想安装其他的版本,可以去下面官网链接,选择其他版本的链接进行拷贝替换)

wget https://nginx.org/download/nginx-1.16.0.tar.gz

解压并安装

tar zxvf nginx-1.16.0.tar.gz
cd nginx-1.16.0
./configure --prefix=/usr/local/nginx
make && make install

添加全局命令

ln -s /usr/local/nginx/sbin/nginx /usr/bin/nginx

测试安装

nginx -v

如下图,则安装成功:

验证服务是否启动成功

netstat -ntlp | grep nginx

如下:

添加nginx服务

vim /lib/systemd/system/nginx.service

将以下内容插入:

[unit]
description=nginx
after=network.target

[service]
type=forking
execstart=/usr/local/nginx/sbin/nginx
execreload=/usr/local/nginx/sbin/nginx -s reload
execstop=/usr/local/nginx/sbin/nginx -s quit
privatetmp=true

[install]
wantedby=multi-user.target

以服务的方式启动nginx

pkill nginx

systemctl start nginx

查看服务是否启动

 systemctl status nginx
 netstat -ntlp | grep nginx

配置nginx服务开机自动启动

systemctl enable nginx

这下子就安装完毕了 ,配置文件在:

vim /usr/local/nginx/conf/nginx.conf

可选:

nginx的版本号默认是打开的,可以在默认的错误页面和http响应头中查看到。

不同版本,特别是低版本的nginx可能存在漏洞,所以如果不希望被别人获取到版本号的话,可以选择进行版本号隐藏。

隐藏nginx版本号

cd /usr/local/nginx/conf
vim nginx.conf

nginx.conf文件的“server_tokens”修改成”off“:

http {
...
server_tokens off;
...
} 

再修改fastcgi.conf

vim fastcgi.conf

修改如下行

fastcgi_param server_software nginx/$nginx_version;
# 改为:
fastcgi_param server_software nginx;

重启nginx

systemctl restart nginx

隐藏版本号完毕

总结

以上所述是小编给大家介绍的linux下安装nginx1.16.0的教程详解,希望对大家有所帮助

如对本文有疑问,请在下面进行留言讨论,广大热心网友会与你互动!! 点击进行留言回复

相关文章:

验证码:
移动技术网