NGINX网站服务

桥接模式

连接到以太网

查看地址

测试ping  www.baidu.com


使用远程连接做如下实验:
关闭防火墙
systemctl stop firewalld
setenforce 0
sestatus

安装服务
yum install gcc-c++  -y
yum -y install \
pcre-devel \
zlib-devel

新建用户
useradd -M -s /sbin/nologin nginx

上传压缩包   解压  切换目录

tar xzvf nginx-1.13.7.tar.gz -C /usr/src/

安装服务
./configure \
--prefix=/usr/local/nginx \
--user=nginx \
--group=nginx \
--with-http_stub_status_module


编译安装
make && make install

软连接
ln -s /usr/local/nginx/sbin/nginx /usr/local/sbin/

nginx -t //配置文件语法检查

nginx //启动服务


-------制作管理角本--------
vi /etc/init.d/nginx
#!/bin/bash
# chkconfig: 35 99 20
# description: Nginx Service Control Script
PROG="/usr/local/nginx/sbin/nginx"
PIDF="/usr/local/nginx/logs/nginx.pid"
case "$1" in
  start)
    $PROG
    ;;
  stop)
    kill -s QUIT $(cat $PIDF)
    ;;
  restart)
    $0 stop
    $0 start
    ;;
  reload)
    kill -s HUP $(cat $PIDF)
    ;;
  *)
        echo "Usage: $0 {start|stop|restart|reload}"
        exit 1
esac
exit 0


修改权限    使Nginx生效
chmod +x /etc/init.d/nginx
chkconfig --add nginx

切换目录
cd /usr/local/nginx/conf/
将原有目录删除
rm -rf nginx.conf
上传文件到/目录下面   将文件复制到下目录

cd /
cp nginx.conf /usr/local/nginx/conf


ulimit -n  65500//查看和更改系统本地打开资源数
ulimit -n 65500 >> /etc/rc.local

cat /usr/local/nginx/logs/access.log
访问http://192.168.0.100/

访问http://192.168.0.100/status/

-----以下配置nginx的验证功能---
yum install httpd-tools  -y
安装服务


htpasswd -c /usr/local/nginx/passwd.db jack   
添加账户和密码  用户为jack 密码为1

chmod 400 /usr/local/nginx/passwd.db
修改权限 只有主人可以读取

切换目录
cd /usr/local/nginx/
修改主人的权限
chown nginx passwd.db
查看


------以下配置虚拟主机功能-------
---基于域名----
cd /usr/local/nginx/conf/
新建
mkdir extra

将下面命令插入
server {
        listen    192.168.0.100:8080;
        server_name  www.bt.com;
        charset utf-8;
        access_log  logs/bt.access.log  main;
        location / {
            root   /var/www/bt;
            index  index.html index.htm;
        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   html;
        }
  }
}
server {
        listen   192.168.0.100:80;
        server_name  www.bc.com;
        charset utf-8;
        access_log  logs/bc.access.log  main;
        location / {
            root   /var/www/bc;
            index  index.html index.htm;
        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   html;
        }
  }

}


解决问题

切换目录查看


复制目录到当前目录


切换目录
cd /usr/local/nginx/conf/

编辑配置文件  添加dns
vim /etc/hosts


-------基于IP的-----


listen       192.168.80.193:80;

---基于端口的-----
listen       192.168.80.193:8080;


--------------以下是安装MYSQL-----http://mirrors.sohu.com/mysql/---
---------------以下安装mysql------------------------
yum -y install \
ncurses \
ncurses-devel \
bison \
Cmake


新建用户
useradd -s /sbin/nologin  mysql


上传压缩包 切换目录
tar xzvf mysql-boost-5.7.20.tar.gz
cd mysql-5.7.20/

安装gcc-c++服务
yum install gcc-c++ -y 


编译安装
make -j 4 && make install  如果报错  使用这个命令多安装几次

修改权限
chown -R mysql.mysql /usr/local/mysql/


编辑配置文件
vi /etc/my.cnf
删除所有
插入下面命令
[client]
port = 3306
default-character-set=utf8
socket = /usr/local/mysql/mysql.sock

[mysql]
port = 3306
default-character-set=utf8
socket = /usr/local/mysql/mysql.sock

[mysqld]
user = mysql
basedir = /usr/local/mysql
datadir = /usr/local/mysql/data
port = 3306
character_set_server=utf8
pid-file = /usr/local/mysql/mysqld.pid
socket = /usr/local/mysql/mysql.sock
server-id = 1

sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES,NO_AUTO_CREATE_USER,NO_AUTO_VALUE_ON_ZERO,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,PIPES_AS_CONCAT,ANSI_QUOTES


修改权限
chown mysql:mysql /etc/my.cnf


自定义变量
echo 'PATH=/usr/local/mysql/bin:/usr/local/mysql/lib:$PATH' >> /etc/profile
echo 'export PATH' >> /etc/profile
source /etc/profile

切换目录
cd /usr/local/mysql/

安装服务

bin/mysqld \
--initialize-insecure \
--user=mysql \
--basedir=/usr/local/mysql \
--datadir=/usr/local/mysql/data

复制
cp usr/lib/systemd/system/mysqld.service /usr/lib/systemd/system/

systemctl daemon-reload
systemctl start mysqld
netstat -anpt | grep 3306


mysqladmin -u root -p password "abc123" //给root账号设置密码    默认回车

mysql -u root

-----------------以下安装PHP-----------

yum -y install \
libjpeg \
libjpeg-devel \
libpng libpng-devel \
freetype freetype-devel \
libxml2 \
libxml2-devel \
zlib zlib-devel \
curl curl-devel \
openssl openssl-devel


上传压缩包


切换到/目录下面  解压
tar xjvf php-7.1.10.tar.bz2

进入压缩文件    
cd php-7.1.10

安装服务
./configure \
--prefix=/usr/local/php \
--with-mysql-sock=/usr/local/mysql/mysql.sock \
--with-mysqli \
--with-zlib \
--with-curl \
--with-gd \
--with-jpeg-dir \
--with-png-dir \
--with-freetype-dir \
--with-openssl \
--enable-mbstring \
--enable-xml \
--enable-session \
--enable-ftp \
--enable-pdo \
--enable-tokenizer \
--enable-zip \
--enable-fpm

安装服务成功 下图

编译安装
make -j 4 && make install

复制
cp php.ini-development /usr/local/php/lib/php.ini

编辑配置文件
vi /usr/local/php/lib/php.ini
搜索mysqli.default_socket 

mysqli.default_socket = /usr/local/mysql/mysql.sock
搜索date.timezone

date.timezone = Asia/Shanghai

/usr/local/php/bin/php -m //验证安装的模块


-----------配置及优化FPM模块--------
cd /usr/local/php/etc/
cp  php-fpm.conf.default php-fpm.conf
cd /usr/local/php/etc/php-fpm.d/
cp www.conf.default www.conf


编辑配置文件
vi php-fpm.conf

pid = run/php-fpm.pid   将前面的分号去掉

;user = nginx
;group = nginx

/usr/local/php/sbin/php-fpm -c /usr/local/php/etc/php.ini
netstat -anpt | grep 9000


ln -s /usr/local/php/bin/* /usr/local/bin/


ps aux | grep -c "php-fpm"  //结果

编辑配置文件   将原本内容删除  重新添加
-----更新启动脚本----------
vi /etc/init.d/nginx
#!/bin/bash
# chkconfig: 35 99 20
# description: Nginx Service Control Script
PROG="/usr/local/nginx/sbin/nginx"
PIDF="/usr/local/nginx/logs/nginx.pid"
PROG_FPM="/usr/local/php/sbin/php-fpm"
PIDF_FPM="/usr/local/php/var/run/php-fpm.pid"
case "$1" in
  start)
    $PROG
    $PROG_FPM
    ;;
  stop)
    kill -s QUIT $(cat $PIDF)
    kill -s QUIT $(cat $PIDF_FPM)
    ;;
  restart)
    $0 stop
    $0 start
    ;;
  reload)
    kill -s HUP $(cat $PIDF)
    ;;
  *)
        echo "Usage: $0 {start|stop|restart|reload}"
        exit 1
esac
exit 0

修改权限
chmod +x /etc/init.d/nginx

--------以下是让nginx支持PHP功能--------

vi /usr/local/nginx/conf/nginx.conf  //在合适的位置
找到404这个位置  添加

location ~ \.php$ {
            root          /var/www/aa;
            fastcgi_pass   127.0.0.1:9000;
            fastcgi_index  index.php;
            fastcgi_param  SCRIPT_FILENAME  /var/www/aa$fastcgi_script_name; //注意目录名称
            include        fastcgi_params;
}


mkdir -p /var/www/aa
vi /var/www/aa/index.php
phpinfo();
?>

在网页测试 http://192.168.0.100/index.php

--------下面测试数据库工作是否正常-----
mysql -u root -p   密码abc123

CREATE DATABASE bbs;
GRANT all ON bbs.* TO 'bbsadm'@'%' IDENTIFIED BY 'admin123';
GRANT all ON bbs.* TO 'bbsadm'@'localhost' IDENTIFIED BY 'admin123';
flush privileges;

vi /var/www/aa/index.php

$link=mysqli_connect('192.168.0.100','bbsadm','admin123');
if($link) echo "

Success!!

";
else echo "Fail!!";
?>


在网页测试  http://192.168.0.100/index.php


---以下安装论坛------
上传软件包


unzip Discuz_X3.4_SC_UTF8.zip  -d /tmp
cd /tmp
cd dir_SC_UTF8/
cp -r upload/ /var/www/aa/bbs
cd /var/www/aa/bbs
chown -R root:nginx ./config/
chown -R root:nginx ./data/
chown -R root:nginx ./uc_client/
chown -R root:nginx ./uc_server/

chmod -R 777 ./config/
chmod -R 777 ./data/
chmod -R 777 ./uc_client/
chmod -R 777 ./uc_server/

http://IP/bbs/install/index.php
http://192.168.0.100/bbs/admin.php  //管理后台

cd /var/www/aa/bbs
mv install/ install.lock
chmod 600 install.lock/

你可能感兴趣的:(linux,linux)