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


LINUX安装nginx详细步骤

1.安装依赖包

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

yum y install gcc zlib zlibdevel pcredevel openssl openssldevel

2.下载并解压安装包

//创建一个文件夹

cd /usr/local

mkdir nginx

cd nginx

//下载tar包

wget nginx.org/download/nginx1.13.7.tar.gz

tar xvf nginx1.13.7.tar.gz

3.安装nginx

//进入nginx目录

cd /usr/local/nginx

//进入目录

cd nginx1.13.7

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

./configure withhttp_stub_status_module withhttp_ssl_module

//执行make命令

make

//执行make install命令

make install

4.启动nginx服务

​​​​​​​/usr/local/nginx/sbin/nginx c /usr/local/nginx/conf/nginxonf

配置nginxonf

打开配置文件

vi /usr/local/nginx/conf/nginxonf

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

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

5.重启nginx

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

查看nginx进程是否启动:

ps ef | grep nginx

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

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

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

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

开放80端口:

firewallcmd zone=public addport=80/tcp permanent

查询端口号80 是否开启:

firewallcmd queryport=80/tcp

重启防火墙:

firewallcmd reload

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

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

安装完成一般常用命令

进入安装目录中,

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

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

./nginx 启动

./nginx s stop 关闭

./nginx s reload 重启

报错

进入objs目录下修改Makefile文件

CFLAGS = pipe O W Wall Wpointerarith Wnounusedparameter ** Werror** g

将 ** Werror** 去掉

错误

安装nginx源

curl o /etc/yum.repos.d/epel.repo mirrors.aliyun/repo/epel7.repo

先安装

yum y install epelrelease

#应该是缺少modules模块

yum y install nginxallmodules.noarch

然后在用nginx t就好了

[root@k8snode2 ~]# nginx t

nginx: the configuration file /etc/nginx/nginxonf syntax is ok

nginx: configuration file /etc/nginx/nginxonf test is successful

添加使用–withstream=dynamic 配置

./configure prefix=/usr/local/nginx/ withstream=dynamic

然后make make install

make

make install


上一篇:做外贸需要哪些样的企业邮箱

下一篇:email帐号最多也是无限个,那我可以设哪些名称的 email网址呢?


Nginx Linux nginx安装 nginx安装教程
Copyright © 2002-2019 测速网 https://www.inhv.cn/ 皖ICP备2023010105号 城市 地区 街道
温馨提示:部分文章图片数据来源与网络,仅供参考!版权归原作者所有,如有侵权请联系删除!
热门搜索