“Nginx服务及部署”的版本间的差异
(→安装配置nginx服务) |
|||
(未显示3个用户的37个中间版本) | |||
第1行: | 第1行: | ||
− | + | ==nginx服务部署== | |
− | + | ===修改主机名=== | |
− | + | 这里我们设置主机名为nginx. | |
− | |||
− | + | [root@localhost /]# '''hostnamectl set-hostname nginx'''(修改主机名) | |
− | |||
+ | [root@localhost /]# '''bash''' (刷新shell命令行) | ||
− | |||
+ | [root@mysql0 /]# '''su -''' (重新登录) | ||
− | |||
+ | [root@mysql0 ~]# '''hostnamectl''' (查看主机信息) | ||
− | |||
+ | [[文件:nginx1.png]] | ||
− | + | == 关闭防火墙和SELinux服务 == | |
− | |||
+ | ===防火墙和SELinux开启关闭教程=== | ||
− | |||
+ | [root@nginx ~]# '''setenforce 0''' (设置关闭 1开启0关闭) | ||
− | |||
+ | [root@nginx ~]# '''systemctl stop firewalld''' (关闭防火墙) | ||
− | |||
+ | [root@nginx ~]# '''getenforce''' (查看进程 Enforcing开启Permissive关闭) | ||
− | |||
+ | Permissive | ||
+ | ===安装配置基础服务=== | ||
− | |||
− | + | [root@nginx src]# '''yum -y install gcc gcc-c++ openssl-devel zlib-devel zlib pcre-devel ''' | |
− | + | (安装编译器) | |
− | [root@nginx | + | [root@nginx src]# '''groupadd -g 1001 nginx''' |
− | + | (创建指定所属组) | |
− | + | [root@nginx src]# '''useradd -u 900 nginx -g nginx -s /sbin/nologin''' | |
+ | |||
+ | |||
+ | (创建指定用户组) | ||
+ | [root@nginx src]# '''tail -l /etc/passwd''' (查看信息) | ||
+ | |||
+ | [[文件:nginx2.png]] | ||
+ | |||
+ | 当我们用tail -l /etc/passwd查看的时候,最后一行出现: | ||
− | + | nginx:x:900:1001::/home/nginx:/sbin/nologin | |
+ | 说明配置OK | ||
− | + | == 安装配置nginx服务 == | |
+ | 在安装这个服务之前,我们需要远程传输的工具。这个工具和Xshell是同款公司出品,叫做Xftp,用它传输更方便快捷。为了防止Xshell和Xftp过期,我们采用家校版本,完全免费试用。下载的官方网址:https://www.netsarang.com/zh/all-downloads/ | ||
− | + | 传输文件的话,我们这里有一种专门传输的工具,就是Xftp,我们使用的时候,一定要选好路径,把我们的nginx压缩包放入/usr/local/src/目录下面,如图所示: | |
+ | [[文件:xftp上传nginx.png]] | ||
− | + | 将nginx安装包放到/usr/local/src目录下 | |
− | |||
− | [root@nginx | + | [root@nginx ~]# '''cd /usr/local/src''' |
+ | |||
+ | [root@nginx src]# '''ls''' | ||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
nginx-1.12.2.tar.gz | nginx-1.12.2.tar.gz | ||
− | [root@nginx src]# tar -zxvf nginx-1.12.2.tar.gz (解压安装包) | + | |
− | [root@nginx src]# cd nginx-1.12.2/ | + | |
+ | [root@nginx src]# '''tar -zxvf nginx-1.12.2.tar.gz''' (解压安装包) | ||
+ | |||
+ | [root@nginx src]# '''cd nginx-1.12.2/''' | ||
+ | |||
运行这个超长命令 | 运行这个超长命令 | ||
− | [root@nginx nginx-1.12.2]# ./configure --prefix=/usr/local/nginx --with-http_dav_module \ | + | |
− | > --with-http_stub_status_module --with-http_addition_module \ | + | |
− | > --with-http_sub_module --with-http_flv_module --with-http_mp4_module \ | + | |
− | > --with-http_ssl_module --with-http_gzip_static_module --user=nginx --group=nginx | + | 下面的代码都得输上: |
+ | |||
+ | '''并且,要注意一个非常重要的问题,就是这里的斜杠的意思是换行的意思,千万不要有空格!!!''' | ||
+ | |||
+ | [root@nginx nginx-1.12.2]# '''./configure --prefix=/usr/local/nginx --with-http_dav_module \''' | ||
+ | |||
+ | > '''--with-http_stub_status_module --with-http_addition_module \''' | ||
+ | |||
+ | > '''--with-http_sub_module --with-http_flv_module --with-http_mp4_module \''' | ||
+ | |||
+ | > '''--with-http_ssl_module --with-http_gzip_static_module --user=nginx --group=nginx''' | ||
+ | |||
+ | |||
+ | 如果输入上述代码,出现错误: | ||
+ | |||
+ | [[文件:经典错误.png|600px]] | ||
+ | |||
+ | '''出现这个错误的原因就是每行代码后面有空格,所以删掉就可以解决了 | ||
+ | ''' | ||
+ | |||
+ | |||
(此处省略运行信息,如果没有报错,可进行编译安装) | (此处省略运行信息,如果没有报错,可进行编译安装) | ||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | [root@nginx nginx-1.12.2]# yum -y install net-tools (安装该工具) | + | [root@nginx src]# '''make && make install''' (编译安装) |
+ | |||
+ | [root@nginx src]# '''ln -s /usr/local/nginx/sbin/nginx /usr/local/sbin/''' (创建软连接) | ||
+ | |||
+ | [root@nginx src]# '''nginx -t''' (查看) | ||
+ | |||
+ | |||
+ | [[文件:nginx3.png]] | ||
+ | |||
+ | |||
+ | [root@nginx nginx-1.12.2]# '''yum -y install net-tools''' (安装该工具) | ||
− | [root@nginx src]# nginx | + | [root@nginx src]# '''nginx''' |
− | [root@nginx src]# netstat -ntpl (查看端口信息,有80端口,浏览器链接本虚拟机ip ,出现欢迎界面说明成功) | + | [root@nginx src]# '''netstat -ntpl''' (查看端口信息,有80端口,浏览器链接本虚拟机ip ,出现欢迎界面说明成功) |
+ | [[文件:启动端口测试.png]] | ||
− | |||
+ | 打开浏览器,输入你的ip地址,我的是192.168.255.102,输入之后回车就会出现欢迎的画面 | ||
− | + | [[文件:nginx4.png | 600px]] | |
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− |
2020年10月24日 (六) 15:25的最新版本
nginx服务部署
修改主机名
这里我们设置主机名为nginx.
[root@localhost /]# hostnamectl set-hostname nginx(修改主机名)
[root@localhost /]# bash (刷新shell命令行)
[root@mysql0 /]# su - (重新登录)
[root@mysql0 ~]# hostnamectl (查看主机信息)
关闭防火墙和SELinux服务
防火墙和SELinux开启关闭教程
[root@nginx ~]# setenforce 0 (设置关闭 1开启0关闭)
[root@nginx ~]# systemctl stop firewalld (关闭防火墙)
[root@nginx ~]# getenforce (查看进程 Enforcing开启Permissive关闭)
Permissive
安装配置基础服务
[root@nginx src]# yum -y install gcc gcc-c++ openssl-devel zlib-devel zlib pcre-devel
(安装编译器)
[root@nginx src]# groupadd -g 1001 nginx
(创建指定所属组)
[root@nginx src]# useradd -u 900 nginx -g nginx -s /sbin/nologin
(创建指定用户组)
[root@nginx src]# tail -l /etc/passwd (查看信息)
当我们用tail -l /etc/passwd查看的时候,最后一行出现:
nginx:x:900:1001::/home/nginx:/sbin/nologin
说明配置OK
安装配置nginx服务
在安装这个服务之前,我们需要远程传输的工具。这个工具和Xshell是同款公司出品,叫做Xftp,用它传输更方便快捷。为了防止Xshell和Xftp过期,我们采用家校版本,完全免费试用。下载的官方网址:https://www.netsarang.com/zh/all-downloads/
传输文件的话,我们这里有一种专门传输的工具,就是Xftp,我们使用的时候,一定要选好路径,把我们的nginx压缩包放入/usr/local/src/目录下面,如图所示:
将nginx安装包放到/usr/local/src目录下
[root@nginx ~]# cd /usr/local/src
[root@nginx src]# ls
nginx-1.12.2.tar.gz
[root@nginx src]# tar -zxvf nginx-1.12.2.tar.gz (解压安装包)
[root@nginx src]# cd nginx-1.12.2/
运行这个超长命令
下面的代码都得输上:
并且,要注意一个非常重要的问题,就是这里的斜杠的意思是换行的意思,千万不要有空格!!!
[root@nginx nginx-1.12.2]# ./configure --prefix=/usr/local/nginx --with-http_dav_module \
> --with-http_stub_status_module --with-http_addition_module \
> --with-http_sub_module --with-http_flv_module --with-http_mp4_module \
> --with-http_ssl_module --with-http_gzip_static_module --user=nginx --group=nginx
如果输入上述代码,出现错误:
出现这个错误的原因就是每行代码后面有空格,所以删掉就可以解决了
(此处省略运行信息,如果没有报错,可进行编译安装)
[root@nginx src]# make && make install (编译安装)
[root@nginx src]# ln -s /usr/local/nginx/sbin/nginx /usr/local/sbin/ (创建软连接)
[root@nginx src]# nginx -t (查看)
[root@nginx nginx-1.12.2]# yum -y install net-tools (安装该工具)
[root@nginx src]# nginx
[root@nginx src]# netstat -ntpl (查看端口信息,有80端口,浏览器链接本虚拟机ip ,出现欢迎界面说明成功)
打开浏览器,输入你的ip地址,我的是192.168.255.102,输入之后回车就会出现欢迎的画面