学无先后,达者为师

网站首页 编程语言 正文

Linux安装Nginx详细教程

作者:Smile sea breeze 更新时间: 2022-09-25 编程语言

安装网址

http://nginx.org/en/download.html

安装依赖包

yum -y install make zlib zlib-devel gcc-c++ libtool  openssl openssl-devel

下载Nginx并解压安装包

//下载tar包之前,前提安装wget
yum install wget

//创建文件
mkdir -p/usr/local/nginx

//下载安装包  安装包可以根据自己的需求修改,上面提到的安装网址,选择合适的路径添加
wget http://nginx.org/download/nginx-1.18.0.tar.gz

//解压文件夹
tar -xvf nginx-1.18.0.tar.gz


安装

//执行命令
./configure --prefix=/usr/local/nginx

//执行make命令
make

//执行make install命令
make install

查看安装版本号

/cd sbin

./nginx -v

检查配置文件正确性

./nginx -v

启动Nginx服务

./nginx

停止Nginx服务

./nginx -s stop

启动完成后查看Nginx进程

ps -ef | grep nginx
[root@localhost sbin]# ps -ef | grep nginx
root       7004      1  0 12:30 ?        00:00:00 nginx: master process ./nginx
nobody     7005   7004  0 12:30 ?        00:00:00 nginx: worker process
root       7014   1297  0 12:31 pts/0    00:00:00 grep --color=auto nginx

确认ip地址

[root@localhost html]# ip addr
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
    inet 127.0.0.1/8 scope host lo
       valid_lft forever preferred_lft forever
    inet6 ::1/128 scope host 
       valid_lft forever preferred_lft forever
2: ens33: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP group default qlen 1000
    link/ether 00:0c:29:8b:5d:72 brd ff:ff:ff:ff:ff:ff
    inet 192.168.179.130/24 brd 192.168.179.255 scope global noprefixroute dynamic ens33
       valid_lft 1439sec preferred_lft 1439sec
    inet6 fe80::17be:75e1:b84:e7af/64 scope link noprefixroute 
       valid_lft forever preferred_lft forever


关闭防火墙

防火墙不关闭,无法显示登录的页面,需要先关闭防火墙

systemctl stop firewalld

刚确认的ip地址输入到游览器

http://192.168.179.130/

在这里插入图片描述


[root@localhost html]# systemctl stop firewalld
[root@localhost html]# cat index.html
<!DOCTYPE html>
<html>
<head>
<title>Welcome to nginx!</title>
<style>
    body {
        width: 35em;
        margin: 0 auto;
        font-family: Tahoma, Verdana, Arial, sans-serif;
    }
</style>
</head>
<body>
<h1>Welcome to nginx!</h1>
<p>If you see this page, the nginx web server is successfully installed and
working. Further configuration is required.</p>

<p>For online documentation and support please refer to
<a href="http://nginx.org/">nginx.org</a>.<br/>
Commercial support is available at
<a href="http://nginx.com/">nginx.com</a>.</p>

<p><em>Thank you for using nginx.</em></p>
</body>
</html>

nginx配置文件修改

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

在这里插入图片描述

修改后重启

[root@localhost conf]# nginx -s reload

补充:

每次从nginx路径下在启动文件比较麻烦,直接在路径下直接启动。
方法如下:

nginx的配置路径修改

[root@localhost /]# vim /etc/profile
[root@localhost /]# source /etc/profile

在这里插入图片描述

重新加载配置文件

[root@localhost /]#./nginx -s reload

原文链接:https://blog.csdn.net/weixin_45428910/article/details/127033407

栏目分类
最近更新