Linux配置nginx

一、Linux配置网络

1、配置文件地址(ens33为网卡名称)

vi /etc/sysconfig/network-scripts/ifcfg-ens33

2、配置静态IP

(1)bootproto=static

(2)onboot=yes

(3)IP地址、子网掩码、网关、dns服务器

例如:

IPADDR=192.168.1.160
NETMASK=255.255.255.0
GATEWAY=192.168.1.1
DNS1=119.29.29.29

3、重启网络配置

systemctl restart network

二、查看Linux的ip

ifconfig

如果提示找不到ifconfig命令,使用yum下载:

yum install ifconfig

如果下载失败,使用yum search 查看ifconfig所属哪个包,再下载依赖包

使用本机Ping一下

三、下载Nginx

0、下载相关依赖

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

1、使用wget联机下载nginx压缩包,例如:

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

2、解压缩

tar -zxvf ./nginx-1.20.1.tar.gz

3、自动配置nginx

cd ./nginx-1.20.1  

./configure --prefix=/usr/nginx-1.20.1

4、配置如果出现如下错误,使用:yum -y install pcre-devel 解决。

./configure: error: the HTTP rewrite module requires the PCRE library.
You can either disable the module by using --without-http_rewrite_module
option, or install the PCRE library into the system, or build the PCRE library
statically from the source with nginx by using --with-pcre= option.

5、安装(配置和安装都是在nginx解压目录下完成的)

make && make install

6、配置环境变量

https://blog.csdn.net/qq_42875895/article/details/104554976

四、启动Nginx,本地访问

1、如果本地不能访问,检查防火墙是否开放80端口,防火墙相关命令如下

systemctl status firewalld //防火墙状态
service firewalld start //启动防火墙
firewall-cmd --zone=public --list-ports //查看已开放的端口
firewall-cmd --permanent --add-port=18567/tcp //添加18567
firewall-cmd --permanent --add-port=8080/tcp //添加8080
firewall-cmd --permanent --add-port=3306/tcp //添加3306
firewall-cmd --reload //添加完毕后重载

五、其他

1、关于开机自启Nginx服务

参考:https://www.cnblogs.com/jepson6669/p/9131217.html 

2、Docker部署

当然,你也可以通过Docker来配置Nginx,参考链接如下:https://www.cnblogs.com/sunshine-wy/p/11310865.html

原文地址:https://www.cnblogs.com/liuyu666/p/15137405.html