二十七、nginx两种安装方式:yum安装、源码编译安装

1、yum安装

1、安装必要的环境:
[root@OLDBOY ~]# yum -y install gcc gcc-c++ autoconf automake make
[root@OLDBOY ~]# yum -y install zlib zlib-devel openssl openssl-devel pcre pcre-devel
确保/etc/yum.repos.d/有Base源和epel源

2、yum install -y nginx 
重启方式: systemctl restart nginx 
查询状态: systemctl status nginx
关闭方式: ststemctl stop nginx

3、部署小游戏,解压到目录,略过
为每一个小游戏新建 *.conf 的文件:(注意:每个.conf文件都需要赋予启动nginx的用户有rw权限):
server {
    listen       访问端口;
    server_name  localhost;
    location / {
        root   /小游戏index.html文件所在的具体路径;
        index  index.html index.htm;
    }
    }
    
4、修改 /usr/local/nginx-1.18/conf/nginx.conf 文件
	在http模块中新增一行:
	
	include      存放一堆小游戏的 .conf 文件的具体路径; # 如 /game/*.conf;(每一行后面的分号,别忘加)
5、重启nginx服务并查看状态,ifconfig查看ip,跟上自定义的游戏端口,浏览器输入访问即可。

3、源码编译安装

1、下载官网源码包:
[root@OLDBOY ~]# wget http://nginx.org/download/nginx-1.18.0.tar.gz           

2、安装必要的环境:
[root@OLDBOY ~]# yum -y install gcc gcc-c++ autoconf automake make
[root@OLDBOY ~]# yum -y install zlib zlib-devel openssl openssl-devel pcre pcre-devel

3、解压源码包并指定安装包存放路径:
[root@OLDBOY ~]# tar xvf nginx-1.18.0.tar.gz -C /tmp/

4、切换到安装包存放路径下:
[root@OLDBOY ~]# cd /tmp/nginx-1.18.0
[root@OLDBOY nginx-1.18.0]# ls
auto  CHANGES  CHANGES.ru  conf  configure  contrib  html  LICENSE  man  README  src
此时还没有Makefile文件

5、执行 ./configure并指定一些安装选项:
[root@OLDBOY nginx-1.18.0]# ./configure --user=nginx --group=nginx --prefix=/usr/local/nginx-1.18
	#指定了启动用户和组,安装路径等
这一步会检查安装环境是否完整,并产生Makefile文件,提供给后续的编译及安装依据
[root@OLDBOY nginx-1.18.0]# ls
auto  CHANGES  CHANGES.ru  conf  configure  contrib  html  LICENSE  Makefile  man  objs  README  src

6、执行编译和安装:
[root@OLDBOY nginx-1.18.0]# make && make install
然后去 /usr/local/nginx-1.18/下面去查看安装完成的nginx

7、如何使用nginx文件名去直接启动nginx,而不用绝对路径,修改 /etc/profile文件,来配置变量名
	1>在最后添加上以下两行内容,且保存退出:
     	    PATH=/usr/local/nginx-1.18/sbin:$PATH
	        export PATH
	2>执行一下:source /etc/profile # 重启配置文件
启动方式:直接输入nginx回车即可;
查询状态:ps -elf |grep [n]ginx
关闭方式:pkill -9 nginx

编辑完整脚本:vim nginx.sh
#/bin/bash
mkdir -p /server/web 
wget -O /server/web/nginx-1.18.0.tar.gz http://nginx.org/download/nginx-1.18.0.tar.gz &>/dev/null
yum install -y gcc gcc++ autoconf automake make &>/dev/null
yum install -y openssl openssl-devel zlib zlib-devel prce prce-devel &>/dev/null
cd /server/web/ && tar xf nginx-1.18.0.tar.gz -C . &>/dev/null
cd nginx-1.18.0/ && ./configure --prefix=/usr/local/nginx-1.18.0 &>/dev/null
make && make install &>/dev/null
echo 'export PATH=$PATH:/usr/local/nginx-1.18.0/sbin' >> /etc/profile
source /etc/profile
nginx
保存退出,执行即可自动安装!

8、部署小游戏,解压到目录,略过
为每一个小游戏新建 *.conf 的文件:(注意:每个.conf文件都需要赋予启动nginx的用户有rw权限):
server {
    listen       访问端口;
    server_name  localhost;
    location / {
        root   /小游戏index.html文件所在的具体路径;
        index  index.html index.htm;
    }
    }

9、修改 /usr/local/nginx-1.18/conf/nginx.conf 文件
	在http模块中新增一行:
	include      存放一堆小游戏的 .conf 文件的具体路径; # 如 /game/*.conf;(每一行后面的分号,别忘加)
10、重启nginx服务并查看状态,ifconfig查看ip,跟上自定义的游戏端口,浏览器输入访问即可。
posted @ 2022-06-09 18:19  秋风お亦冷  阅读(340)  评论(0编辑  收藏  举报