系统相关
首页 > 系统相关> > NGINX网站服务

NGINX网站服务

作者:互联网

NGINX网站服务

NGINX网站服务

先准备一个环境

先替换

[root@client1 ~]# systemctl stop firewalld
[root@client1 ~]# setenforce 0
[root@client1 ~]# sed -i '/SELINUX/s/SELINUX=enforcing/SELINUX=disabled/g' /etc/selinux/config
[root@client1 ~]# grep -v "#" /etc/selinux/config 
SELINUX=disabledSELINUXTYPE=targeted 

安装yum源

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

在解决压缩包 和编译安装

tar zxvf nginx-1.12.2.tar.gz 
cd nginx-1.12.2/
 ./configure --prefix=/usr/local/nginx --user=nginx --group=nginx --whith-http_stub_status_module
 make && make install
 ln -s /usr/local/nginx/sbin/nginx /usr/local/sbin/

配置文件语法检查

[root@client1 ~]# 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@client1 ~]# nginx 
[root@client1 ~]# netstat -anpt | grep nginx
tcp        0      0 0.0.0.0:80              0.0.0.0:*               LISTEN      58287/nginx: master 
[root@client1 ~]# killall -1 nginx
[root@client1 ~]# netstat -anpt | grep nginx
tcp        0      0 0.0.0.0:80              0.0.0.0:*               LISTEN      58287/nginx: master 

写脚本

[root@client1 ~]# vim /etc/init.d/nginx
#!/bin/bash
#chkconfig: 35 80 20
#description:Nginx HTTP Server
PROG="/usr/local/nginx/sbin/nginx"
PIDF="/usr/local/nginx/logs/nginx.pid"
case "$1" in
      start)
      $PROG
      ;;
      stop)
      kill -s QUIT $(cat $PIDF)
      ;;
      reload)
      kill -s HUP $(cat $PIDF)
      ;;
      restart)
      $0 stop
      $0 start
      ;;
      *)
      echo "Usage: $0 {start|stop|restart|reload}"
      exit 1
esac
exit 0

[root@client1 ~]# chmod +x /etc/init.d/nginx 
[root@client1 ~]# chkconfig --add nginx
[root@client1 ~]# chkconfig --list
注:该输出结果只显示 SysV 服务,并不包含原生 systemd 服务。SysV 配置数据可能被原生 systemd 配置覆盖。 
      要列出 systemd 服务,请执行 'systemctl list-unit-files'。      查看在具体 target 启用的服务请执行      'systemctl list-dependencies [target]'。
netconsole     	0:关	1:关	2:关	3:关	4:关	5:关	6:关network        	0:关	1:关	2:开	3:开	4:开	5:开	6:关nginx          	0:关	1:关	2:关	3:开	4:关	5:开	6:关

在做软连接和 修改配置文件

[root@client1 ~]# ln -s /usr/local/nginx/conf/nginx.conf /etc/
[root@client1 ~]# vi /etc/nginx.conf 
[root@client1 ~]# nginx -t
nginx: the configuration file /usr/local/nginx/conf/nginx.conf syntax is oknginx: [warn] 4096 worker_connections exceed open file resource limit: 1024nginx: configuration file /usr/local/nginx/conf/nginx.conf test is successful
[root@client1 ~]# ulimit -n 
1024
[root@client1 ~]# ulimit -n 65535 >> /etc/rc.local 
[root@client1 ~]# ulimit -n 
65535
打开网址:20.0.0.10

在这里插入图片描述
在这里插入图片描述

查看日志情况 和请求数

[root@client1 ~]# cd /usr/local/nginx/logs/
[root@client1 logs]# ll
-rw-r--r--. 1 root root  637 11月 30 16:22 aa.com.access.log
-rw-r--r--. 1 root root    0 11月 30 15:12 access.log
-rw-r--r--. 1 root root 1775 11月 30 16:22 error.log
-rw-r--r--. 1 root root    5 11月 30 16:19 nginx.pid
[root@client1 logs]# vi aa.com.access.log 
[root@client1 logs]# cat aa.com.access.log 
20.0.0.3 - - [30/Nov/2020:16:21:10 +0800] "GET / HTTP/1.1" 200 612 "-" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/70.0.3538.102 Safari/537.36 Edge/18.18363" "-"20.0.0.3 - - [30/Nov/2020:16:22:37 +0800] "GET /stats HTTP/1.1" 404 571 "-" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/70.0.3538.102 Safari/537.36 Edge/18.18363" "-"20.0.0.3 - - [30/Nov/2020:16:22:37 +0800] "GET /favicon.ico HTTP/1.1" 404 571 "-" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/70.0.3538.102 Safari/537.36 Edge/18.18363" "-"
[root@client1 logs]# cat aa.com.access.log | wc -l
3

yum源安装 并且创建一个用户 和授权

[root@client1 ~]# yum -y install httpd-tools
已安装:  httpd-tools.x86_64 0:2.4.6-67.el7.centos                                        
完毕!
root@client1 ~]# htpasswd -c /usr/local/nginx/passwd.db jack
New password: 
Re-type new password: 
Adding password for user jack
[root@client1 ~]# chown nginx /usr/local/nginx/passwd.db 
[root@client1 ~]# vi /etc/nginx.conf 
[root@client1 ~]# nginx -t
nginx: the configuration file /usr/local/nginx/conf/nginx.conf syntax is oknginx: [warn] 4096 worker_connections exceed open file resource limit: 1024nginx: configuration file /usr/local/nginx/conf/nginx.conf test is successful
[root@client1 ~]# systemctl stop nginx
[root@client1 ~]# systemctl start nginx

在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述

建立虚拟主机

[root@client1 ~]# vi /etc/nginx.conf
在这里插入图片描述
在末尾添加配置文件

[root@client1 ~]# curl http://www.aa.com
[root@client1 ~]# echo "<h1>this is server aa site.</h1>" > /var/www/aa/index.html 
[root@client1 ~]# curl http://www.aa.com
[root@client1 ~]# vi /usr/local/nginx/html/index.html 
[root@client1 ~]# curl http://www.aa.com
<h1>this is server aa site.</h1>

添加虚拟地址

[root@client1 ~]# ifconfig ens33:1 192.168.1.10/24
[root@client1 ~]# ifconfig 
ens33: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500        inet 20.0.0.10  netmask 255.255.255.0  broadcast 20.0.0.255        inet6 fe80::8151:49c2:edaa:e376  prefixlen 64  scopeid 0x20<link>        ether 00:0c:29:18:3c:39  txqueuelen 1000  (Ethernet)        RX packets 7650  bytes 1587559 (1.5 MiB)        RX errors 0  dropped 0  overruns 0  frame 0        TX packets 4431  bytes 578311 (564.7 KiB)        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0
ens33:1: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500        inet 192.168.1.10  netmask 255.255.255.0  broadcast 192.168.1.255        ether 00:0c:29:18:3c:39  txqueuelen 1000  (Ethernet)

添加命令行
在这里插入图片描述
在这里插入图片描述


[root@client1 ~]# netstat -apnt | grep nginx
tcp        0      0 192.168.1.10:80         0.0.0.0:*               LISTEN      4931/nginx: master  tcp        0      0 20.0.0.10:80            0.0.0.0:*               LISTEN      4931/nginx: master  
[root@client1 ~]# curl http://192.168.1.10
<h1>this is server ab site.</h1>
[root@client1 ~]# curl http://20.0.0.10
<h1>this is server aa site.</h1>

更改监听端口
在这里插入图片描述
在这里插入图片描述

yum 源安装

[root@client1 ~]# yum -y install ncurses ncurses-devel bison cmake
已安装:  cmake.x86_64 0:2.8.12.2-2.el7      ncurses-devel.x86_64 0:5.9-13.20130511.el7     
完毕!

创建一个运行用户
[root@client1 ~]# useradd -s /sbin/nologin mysql
解压缩包
[root@client1 ~]# tar zxvf mysql-boost-5.7.20.tar.gz
在这里插入图片描述
设置属主 和属组
[root@client1 ~]# chown -R mysql.mysql /usr/local/mysql/
修改配置文件

[root@client1 ~]# vi /etc/my.cnf
[client]
port = 3306default-character-set = utf8socket = /usr/local/mysql/mysql.sock
[mysql]
port = 3306default-character-set = utf8socket = /usr/local/mysql/mysql.sock
[mysqld]
user = mysqlbasedir = /usr/local/mysqldatadir = /usr/local/mysql/dataport = 3306character_set_server = utf8pid-file = /usr/local/mysql/mysqld.pidsocket = /usr/local/mysql/mysql.sockserver-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
[root@client1 ~]# chown mysql.mysql /etc/my.cnf
[root@client1 ~]# echo ' PATH=/usr/local/mysql/bin:/usr/local/mysql/lib:$PATH ' >> /etc/profile
[root@client1 ~]# source /etc/profile
[root@client1 ~]# echo $PATH
/usr/local/mysql/bin:/usr/local/mysql/lib:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/root/bin

数据库初始化

先生成一个空密码:[root@client1 ~]# mysqld --initalize-insecure
[root@client1 ~]# mysqld --initialize-insecure --user=mysql --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data
拷贝:[root@client1 mysql]# cp usr/lib/systemd/system/mysqld.service /usr/lib/systemd/system
启动服务:root@client1 mysql]# systemctl start mysqld

数据库开启自启 关闭 状态

[root@client1 mysql]# systemctl start mysqld
[root@client1 mysql]# systemctl enable mysqld
Created symlink from /etc/systemd/system/multi-user.target.wants/mysqld.service to /usr/lib/systemd/system/mysqld.service.
[root@client1 mysql]# systemctl status mysqld
● mysqld.service - MySQL Server   Loaded: loaded (/usr/lib/systemd/system/mysqld.service; enabled; vendor preset: disabled)   Active: active (running) since 二 2020-12-01 14:51:51 CST; 1min 34s ago     Docs: man:mysqld(8)           http://dev.mysql.com/doc/refman/en/using-systemd.html Main PID: 31483 (mysqld)   CGroup: /system.slice/mysqld.service           └─31483 /usr/local/mysql/bin/mysqld --daemonize --pid...

[root@client1 mysql]# netstat -apnt | grep 3306
tcp6       0      0 :::3306                 :::*                    LISTEN      31483/mysqld     
[root@client1 mysql]# mysql
mysql> exit
Bye
修改密码
[root@client1 mysql]# mysqlmysql> use mysql;mysql> set password = password('abc123');

安装配置PHP 解析环境

安装环境依赖包

[root@client1 mysql]# yum -y install libjpeg libjpeg-devel libpng libpng-devel libxml2 libxml2-devel zlib zlib-devel curl curl-devel openssl openssl-devel freetype freetype-devel解压包:tar jxvf 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-fpm --enable-mbstring --enable-xml --enable-session --enable-ftp --enable-pdo --enable-tokenizer --enable-zip 
make && make install
cp php.ini-development /usr/local/php/lib/php.ini
修改配置文件
vi /usr/local/php/lib/php.ini 

在这里插入图片描述
在这里插入图片描述

配置及优化FPM模块

[root@client1 php-7.1.10]# cd /usr/local/php/etc/
[root@client1 etc]# cp php-fpm.conf.default php-fpm.conf
[root@client1 etc]# cd /usr/local/php/etc/php-fpm.d/
[root@client1 php-fpm.d]# cp www.conf.default www.conf
[root@client1 php-fpm.d]# cd /usr/local/php/etc/
[root@client1 etc]# vi php-fpm.conf
[root@client1 etc]# cd

在这里插入图片描述

[root@client1 ~]# /usr/local/php/sbin/php-fpm -c /usr/local/php/lib/php.ini 
[root@client1 ~]# netstat -anpt | grep 9000
tcp        0      0 127.0.0.1:9000          0.0.0.0:*               LISTEN      37838/php-fpm: mast 
[root@client1 ~]# ln -s /usr/local/php/bin/* /usr/bin/

让Nginx支持php功能

[root@client1 ~]# vi /etc/nginx.conf 

在这里插入图片描述

[root@client1 ~]# systemctl stop nginx
[root@client1 ~]# systemctl start nginx
[root@client1 ~]# vi /usr/local/nginx/html/index.php

在这里插入图片描述
实验效果
在这里插入图片描述

mysql> create database bbs;Query OK, 1 row affected (0.02 sec)
mysql> show databases;
+--------------------+
| Database           |
+--------------------+|
 information_schema |
 | bbs                |
 | mysql              |
 | performance_schema |
 | sys                |
 +--------------------+5 rows in set (0.00 sec)
 mysql> grant all privileges on bbs.* to 'bbsuser'@'%' identified by 'admin123';
 Query OK, 0 rows affected, 1 warning (0.01 sec)
mysql> grant all privileges on bbs.* to 'bbsuser'@'localhost' identified by 'admin123';
Query OK, 0 rows affected, 1 warning (0.00 sec)
mysql> flush privileges; 
Query OK, 0 rows affected (0.00 sec)
mysql> exit
Bye

###  修改配置文件
```javascript
[root@client1 ~]# vi /usr/local/nginx/html/index.php
<?php$link=mysqli_connect ('20.0.0.10',''admin123');if($link) echo "<h1>Success!!!!</h1>;"else echo "Fail!!!"?>

在这里插入图片描述

安装论坛

解压包
unzip Discuz_X3.4_SC_UTF8.zip
一系列命令
292 cd dir_SC_UTF8/
293 cp -r upload/ /usr/local/nginx/html/bbs
294 cd /usr/local/nginx/html/bbs/
295 chown -R root.nginx ./data/
296 chown -R root.nginx ./uc_client/
297 chown -R root.nginx ./uc_server/
298 chmod -R 777 ./config/
299 chmod -R 777 ./data/
300 chmod -R 777 ./uc_client/
301 chmod -R 777 ./uc_server/
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述

标签:服务,nginx,网站,client1,local,NGINX,usr,mysql,root
来源: https://blog.csdn.net/weixin_50346902/article/details/110435532