Py学习  »  NGINX

Nginx网站服务

将逝未逝的青舂 • 4 年前 • 236 次点击  

Nginx

一款高性能、轻量级web服务软件

(1)稳定性高
(2)系统资源消耗低
(3)对HTTP并发连接的处理能力高
单台物理服务器可支持30000~50000个并发请求

Nginx编译安装

将安装文件包挂载到虚拟机上并查看


[root@localhost ~]# mount.cifs //192.168.100.3/LAMP8 /mnt
Password for root@//192.168.100.3/LAMP8:  
[root@localhost ~]# cd /mnt
[root@localhost mnt]# ls 
Discuz_X3.4_SC_UTF8.zip    nginx-1.12.0.tar.gz  php-7.1.10.tar.bz2
mysql-boost-5.7.20.tar.gz  nginx-1.12.2.tar.gz  php-7.1.20.tar.gz
[root@localhost mnt]# 

将Nginx安装包解压到/opt/目录下

[root@localhost mnt]# tar zxvf nginx-1.12.2.tar.gz -C /opt/

安装支持软件

[root@localhost opt]# yum install gcc gcc-c++ pcre-devel zlib-devel make -y

创建运行用户、组

[root@localhost opt]# useradd -M -s /sbin/nologin nginx

编译安装Nginx

[root@localhost opt]# cd nginx-1.12.2/
[root@localhost nginx-1.12.2]# ls
auto     CHANGES.ru  configure  html     man     src
CHANGES  conf        contrib    LICENSE  README
[root@localhost nginx-1.12.2]# ./configure \
> --prefix=/usr/local/nginx \
> --user=nginx \
> --group=nginx \
> --with-http_stub_status_module

[root@localhost nginx-1.12.2]# make && make install

nginx命令执行路劲优化

[root@localhost nginx-1.12.2]# ln -s /usr/local/nginx/sbin/nginx /usr/local/sbin/
[root@localhost nginx-1.12.2]# nginx -t          //检查配置文件
nginx: the configuration file /usr/local/nginx/conf/nginx.conf syntax is ok
nginx: configuration file /usr/local/nginx/conf/nginx.conf test is successful
[root@localhost nginx-1.12.2]# nginx            //启动nginx
[root@localhost nginx-1.12.2]# netstat -ntap | grep 80       //查看端口
tcp        0      0 0.0.0.0:80              0.0.0.0:*               LISTEN      20716/nginx: master 

关闭防火墙和安全功能

[root@localhost nginx-1.12.2]# systemctl stop firewalld.service 
[root@localhost nginx-1.12.2]# setenforce 0

安装测试包,查看服务是否正常运行

[root@localhost nginx-1.12.2]# yum install elinks -y
[root@localhost nginx-1.12.2]# elinks httpd://localhost

在这里插入图片描述 通过浏览器查看,输入自己的IP地址
在这里插入图片描述 制作管理脚本

[root@localhost logs]# cd /etc/init.d/
[root@localhost init.d]# ls
functions  netconsole  network  README
[root@localhost init.d]# vim nginx
#!/bin/bash
# chkconfig: - 99 20
# description: Nginx Service Control Script
PROG="/usr/local/nginx/sbin/nginx"
PIOF="/usr/local/nginx/sbin/nginx"
case "$1" in
  start)
    $PROG
    ;;
  stop)
    kill -s QUIT $(cat $PIOF)
    ;;
  restart)
    $0 stop
    $0 start
    ;;
  reload)
    kill -s HUP $(cat $PIOF)
    ;;
  *)
       echo "Usage: $0 {start|stop|restart|reload}"
       exit 1
esac
exit 0

[root@localhost init.d]


    
# chmod +x nginx     //给nginx给与执行权限
[root@localhost init.d]# chkconfig --add nginx    //将nginx添加到service
然后我们的服务就可以通过service来控制服务的启动

修改nginx.conf配置文件

[root@localhost init.d]# cd /usr/local/nginx/
[root@localhost nginx]# ls
client_body_temp  fastcgi_temp  logs        sbin       uwsgi_temp
conf              html          proxy_temp  scgi_temp
[root@localhost nginx]# cd conf/
[root@localhost conf]# ls
fastcgi.conf            koi-win             scgi_params
fastcgi.conf.default    mime.types          scgi_params.default
fastcgi_params          mime.types.default  uwsgi_params
fastcgi_params.default  nginx.conf          uwsgi_params.default
koi-utf                 nginx.conf.default  win-utf
[root@localhost conf]# vim nginx.conf

在这里插入图片描述 在这里插入图片描述 #### 安装DNS服务,并配置DNS服务

[root@localhost conf]# yum install bind -y

配置主配置文件
在这里插入图片描述 配置区域配置文件

在这里插入图片描述 配置区域数据配置文件

[root@localhost conf]# cd /var/named
[root@localhost named]# cp -p named.localhost kgc.com.zone
[root@localhost named]# vim kgc.com.zone 

在这里插入图片描述 开启DNS服务
[root@localhost named]# systemctl start named

开启一台win10,测试

在这里插入图片描述

Python社区是高质量的Python/Django开发社区
本文地址:http://www.python88.com/topic/49434
 
236 次点击