Linux环境安装nginx详细步骤及nginx配置

LINUX安装nginx详细步骤

1.安装依赖包

//一键安装上面四个依赖

yum -y install gcc zlib zlib-devel pcre-devel openssl openssl-devel

2.下载并解压安装包

//创建一个文件夹

cd /usr/local

mkdir nginx

cd nginx

//下载tar包

wget http://nginx.org/download/nginx-1.13.7.tar.gz

tar -xvf nginx-1.13.7.tar.gz

3.安装nginx

//进入nginx目录

cd /usr/local/nginx

//进入目录

cd nginx-1.13.7

//执行命令 考虑到后续安装ssl证书 添加两个模块

./configure --with-http_stub_status_module --with-http_ssl_module

//执行make命令

make

//执行make install命令

make install

4.启动nginx服务

 ​​​​​​​/usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf

配置nginx.conf

打开配置文件

vi /usr/local/nginx/conf/nginx.conf

将端口号改成8089(随便挑个端口),因为可能apeache占用80端口,apeache端口尽量不要修改,我们选择修改nginx端口。

将localhost修改为你服务器的公网ip地址。

5.重启nginx

/usr/local/nginx/sbin/nginx -s reload

查看nginx进程是否启动:

ps -ef | grep nginx

6.若想使用外部主机访问nginx,需要关闭服务器防火墙或开放nginx服务端口,端口为上一步nginx.conf的配置端口:

centOS6及以前版本使用命令: systemctl stop iptables.service

centOS7关闭防火墙命令: systemctl stop firewalld.service

关闭防火墙会导致服务器有一定风险,所以建议是单独开放服务端口 :

开放80端口:

firewall-cmd --zone=public --add-port=80/tcp --permanent

查询端口号80 是否开启:

firewall-cmd --query-port=80/tcp

重启防火墙:

firewall-cmd --reload

随后访问该ip:端口 即可看到nginx界面。

7.访问服务器ip查看(备注,由于我监听的仍是80端口,所以ip后面的端口号被省略)

安装完成一般常用命令

进入安装目录中,

命令: cd /usr/local/nginx/sbin

启动,关闭,重启,命令:

./nginx 启动

./nginx -s stop 关闭

./nginx -s reload 重启

报错

LINUX安装nginx详细步骤

进入objs目录下修改Makefile文件

CFLAGS =  -pipe  -O -W -Wall -Wpointer-arith -Wno-unused-parameter **- Werror** -g

将 **- Werror** 去掉

错误

LINUX安装nginx详细步骤

安装nginx源

curl -o /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-7.repo

先安装

yum -y install epel-release

#应该是缺少modules模块

yum -y install nginx-all-modules.noarch

然后在用nginx -t就好了

[root@k8s-node2 ~]# nginx -t

nginx: the configuration file /etc/nginx/nginx.conf syntax is ok

nginx: configuration file /etc/nginx/nginx.conf test is successful

添加使用–with-stream=dynamic 配置

./configure --prefix=/usr/local/nginx/ --with-stream=dynamic

然后make make install

make

make install 

本文地址:https://www.idcbest.com/hostnews/11008736.html



天下数据手机站 关于天下数据 联系我们 诚聘英才 付款方式 帮助中心 网站备案 解决方案 域名注册 网站地图

天下数据18年专注海外香港服务器、美国服务器、海外云主机、海外vps主机租用托管以及服务器解决方案-做天下最好的IDC服务商

《中华人民共和国增值电信业务经营许可证》 ISP证:粤ICP备07026347号

朗信天下发展有限公司(控股)深圳市朗玥科技有限公司(运营)联合版权

深圳总部:中国.深圳市南山区深圳国际创新谷6栋B座10层 香港总部:香港上環蘇杭街49-51號建安商業大廈7樓

7×24小时服务热线:4006388808香港服务电话:+852 67031102

本网站的域名注册业务代理北京新网数码信息技术有限公司的产品

工商网监图标