Nginx网站服务
结构
编译安装Nginx
挂载
[root@centos01 ~]# mount /dev/sr0 /mnt/
删除系统源
[root@centos01 ~]# rm -rf /etc/yum.repos.d/CentOS-*
安装依赖程序pcre-devel 和 zlib-devel
[root@centos01 ~]# yum -y install pcre-devel zlib-devel
创建管理Nginx用户组
[root@centos01 ~]# useradd -M -s /sbin/nologin nginx
切换光盘Linux.iso
[root@centos01 ~]# umount /mnt/
挂载光盘
[root@centos01 ~]# mount /dev/sr0 /mnt/
解压到指定位置
[root@centos01 ~]# tar zxvf /mnt/nginx-1.6.0.tar.gz -C /usr/src/
进入/usr/src/nginx-1.6.0/
[root@centos01 ~]# cd /usr/src/nginx-1.6.0/
配置Nginx
[root@centos01 nginx-1.6.0]# ./configure --prefix=/usr/local/nginx --user=nginx --group=nginx --with-http_stub_status_module
编译安装Nginx
[root@centos01 nginx-1.6.0]# make && make install
优化命令
[root@centos01 nginx-1.6.0]# ln -s /usr/local/nginx/* /usr/local/sbin/
检查nginx配置文件的完整性
[root@centos01 ~]# nginx -t
启动Nginx
[root@centos01 ~]# nginx
重新启动Nginx
[root@centos01 ~]# killall -s HUP nginx
[root@centos01 ~]# killall -1 nginx
停止Nginx
[root@centos01 ~]# killall -s QUIT nginx
[root@centos01 ~]# killall -3 nginx
编辑配置文件
[root@centos01 ~]# vim /etc/init.d/nginx
#!/bin/bash
#chkconfig:35 90 30
#description: Nginx 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)
;;
restart)
$0 stop
$0 start
;;
reload)
kill -s HUB $(cat $PIDF)
;;
*)
echo "Usage: $0 (start | stop | restart | reload)"
exit 1
esac
exit 0
给配置文件增加执行权限
[root@centos01 ~]# chmod +x /etc/init.d/nginx
开启服务
[root@centos01 ~]# chkconfig --add nginx
[root@centos01 ~]# chkconfig --level 35 nginx on
停止服务
[root@centos01 ~]# killall nginx
开启服务
[root@centos01 ~]# systemctl start nginx
配置Nginx虚拟主机
备份配置文件
[root@centos01 ~]# cp /usr/local/nginx/conf/nginx.conf /usr/local/nginx/conf/nginx.conf.bak
编辑配置文件
[root@centos01 ~]# vim /usr/local/nginx/conf/nginx.conf
:%g/^$/d //删除空行
2 user nginx; //管理Nginx的默认用户
创建网站根目录
创建主机根目录
[root@centos01 ~]# mkdir /var/www
创建第一个虚拟主机网站根
[root@centos01 ~]# mkdir /var/www/benetcom
[root@centos01 ~]# echo "www.benet.com" > /var/www/benetcom/index.html
创建第二个虚拟主机网站根
[root@centos01 ~]# mkdir /var/www/accpcom
[root@centos01 ~]# echo "www.accp.com" > /var/www/accpcom/index.html
修改主配置文件
[root@centos01 ~]# vim /usr/local/nginx/conf/nginx.conf
2 user nginx; //管理Nginx用户
3 worker_processes 1; //nginx进程
8 events {
9 worker_connections 1024; //一个进程最大访问并发1024
10 }
11 http { //虚拟主机全局配置
23server { //第一个虚拟主机
24 listen 192.168.100.10:80; //虚拟主机监听IP地址端口
25 server_name www.benet.com; //虚拟主机域名
26 charset utf-8; //字符编码
27 access_log logs/host.access.log; //成功日志
28 location / { //虚拟主机根信息
29 root /var/www/benetcom; //虚拟主机根目录
30 index index.html index.htm; //虚拟主机的主页
31 }
32}
50 server { //第二个虚拟主机
51 listen 192.168.100.10:8080;
52 server_name www.accp.com;
53 charset utf-8;
54 access_log logs/www.accp.com.access_log;
55 location / {
56 root /var/www/accpcom;
57 index index.html index.htm;
58 }
59 }
检查配置文件
[root@centos01 ~]# nginx -t
启动nginx
[root@centos01 ~]# nginx
编辑快速解析文件
[root@centos01 ~]# vim /etc/hosts
192.168.100.10 www.benet.com
192.168.100.20 www.accp.com
开启win7客户端
ip:192.168.100.30
进入C:\Windows\System32\drivers\etc\hosts
添加
192.168.100.10 www.benet.com
192.168.100.10 www.accp.com
然后访问www.benet.com
安装Mysql
安装依赖ncurses-devel和cmake
[root@centos01 ~]# yum -y install ncurses-devel cmake
创建Mysql组
[root@centos01 ~]# groupadd mysql
创建mysql用户
[root@centos01 ~]# useradd -M -s /sbin/nologin -g mysql mysql
卸载光盘
[root@centos01 ~]# umount /mnt/
切换光盘LAMP.iso
[root@centos01 ~]# mount /dev/sr0 /mnt/
解压mysql到指定位置
[root@centos01 ~]# tar zxvf /mnt/mysql-5.5.22.tar.gz -C /usr/src/
进入/usr/src/mysql-5.5.22/
[root@centos01 ~]# cd /usr/src/mysql-5.5.22/
配置安装
[root@centos01 mysql-5.5.22]# cmake -DCMAKE_INSTALL_PREFIX=/usr/local/mysql -DDEFAULT_CHARSET=utf8 -DDEFAULT_COLLATION=utf8_general_ci -DWITH_EXTRA_CHARSETS=all -DSYSCONFDIR=/etc/
编译安装
[root@centos01 mysql-5.5.22]# make && make install
生成配置文件
[root@centos01 mysql-5.5.22]# cp support-files/my-medium.cnf /etc/my.cnf
[root@centos01 mysql-5.5.22]# cp support-files/mysql.server /etc/init.d/mysqld
添加一个执行权限
[root@centos01 mysql-5.5.22]# chmod +x /etc/init.d/mysqld
启动服务
[root@centos01 ~]# chkconfig --add mysqld
[root@centos01 ~]# chkconfig --level 35 mysqld on
优化命令
[root@centos01 ~]# vim /etc/profile
PATH=$PATH:/usr/local/mysql/bin/
[root@centos01 ~]# source /etc/profile
配置所属
[root@centos01 ~]# chown -R mysql:mysql /usr/local/mysql/
初始化mysql
[root@centos01 ~]# /usr/local/mysql/scripts/mysql_install_db --user=mysql --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data
启动mysql服务
[root@centos01 ~]# systemctl start mysqld
设置mysql密码
[root@centos01 ~]# mysqladmin -uroot password
登录mysql
[root@centos01 ~]# mysql -uroot -ppwd@123
Mysql安装完成
安装php
挂载系统光盘
[root@centos01 ~]# mount /dev/sr0 /mnt/
安装php依赖工具
[root@centos01 ~]# yum -y install gd libxml2-devel libjpeg-devel libpng-devel
切换光盘Linux-挂载-解压
[root@centos01 ~]# tar zxvf /mnt/php-5.3.28.tar.gz -C /usr/src/
[root@centos01 ~]# tar zxvf /mnt/ZendGuardLoader-php-5.3-linux-glibc23-x86_64.tar.gz -C /usr/src/
[root@centos01 ~]# cp /mnt/Discuz_X3.2_SC_UTF8.zip /usr/src/
进入/usr/src/php-5.3.28/
[root@centos01 ~]# cd /usr/src/php-5.3.28/
配置php
[root@centos01 php-5.3.28]# ./configure --prefix=/usr/local/php --with-gd --with-zlib --with-mysql=/usr/local/mysql/ --with-mysqli=/usr/local/mysql/bin/mysql_config --with-config-file-path=/usr/local/php --enable-mbstring --enable-fpm --with-jpeg-dir=/usr/lib/
编译安装
[root@centos01 php-5.3.28]# make && make install make
查看安装是否完成
[root@centos01 php-5.3.28]# ls -ld /usr/local/php/
生成主配置文件
[root@centos01 php-5.3.28]# cp php.ini-production /usr/local/php/php.ini
优化php命令
[root@centos01 ~]# ln -s /usr/local/php/bin/* /usr/local/bin/
[root@centos01 ~]# ln -s /usr/local/php/sbin/* /usr/local/sbin/
加载加速模块
[root@centos01 ~]# cd /usr/src/ZendGuardLoader-php-5.3-linux-glibc23-x86_64/php-5.3.x/
[root@centos01 php-5.3.x]# cp ZendGuardLoader.so /usr/local/php/lib/php/
[root@centos01 ~]# vim /usr/local/php/php.ini
[PHP]
zend_extension=/usr/local/php/lib/php/ZendGuardLoader.so
zend_loader.enable=1
配置php-fpm
[root@centos01 ~]# cp /usr/local/php/etc/php-fpm.conf.default /usr/local/php/etc/php-fpm.conf
[root@centos01 ~]# vim /usr/local/php/etc/php-fpm.conf
user = nginx
group = nginx
启动php-fpm进程
[root@centos01 ~]# php-fpm
编辑配置文件
[root@centos01 ~]# vim /usr/local/nginx/conf/nginx.conf
36 location ~ \.php$ {
37 root /var/www/benetcom/;
38 fastcgi_pass 127.0.0.1:9000;
39 fastcgi_index index.php;
40 include fastcgi.conf;
41 #include fastcgi_params;
42 }
检查配置文件有无错误
[root@centos01 ~]# nginx -t
配置php主页
[root@centos01 ~]# vim /var/www/benetcom/index.php
<?php
phpinfo();
?>
编辑配置文件添加index.php
[root@centos01 ~]# vim /usr/local/nginx/conf/nginx.conf
使用win7访问php
配置Nginx支持LAMP平台
修改Nginx主配置文件
[root@centos01 ~]# vim /usr/local/nginx/conf/nginx.conf
server {
listen 192.168.100.10:8080;
server_name www.accp.com;
charset utf-8;
access_log logs/www.accp.com.access_log;
location / {
root /var/www/accpcom;
index index.html index.htm index.php;
}
location ~ \.php$ {
root /var/www/accpcom/;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
include fastcgi.conf;
}
}
设置php测试页
[root@centos01 ~]# vim /var/www/accpcom/index.php
<?php
phpinfo();
?>
重启nginx服务
[root@centos01 ~]# killall nginx
[root@centos01 ~]# nginx
访问测试LNMP
在LAMP平台发布论坛
进入/usr/src/
[root@centos01 ~]# cd /usr/src/
解压Discuz_X3.2_SC_UTF8.zip
[root@centos01 src]# unzip Discuz_X3.2_SC_UTF8.zip
进入/var/www/accpcom/
[root@centos01 upload]# cd /var/www/accpcom/
删除 index.html index.php、
[root@centos01 accpcom]# rm -rf ./*
进入/usr/src/upload/
[root@centos01 ~]# cd /usr/src/upload/
移动论坛项目到虚拟主机网站根目录
[root@centos01 upload]# mv ./* /var/www/accpcom/
设置目录权限和所有者
[root@centos01 ~]# chmod -R 755 /var/www/accpcom/
[root@centos01 ~]# chown -R nginx:nginx /var/www/accpcom/
创建论坛数据授权访问
[root@centos01 ~]# mysql -uroot -ppwd@123
mysql> create database bbs;
mysql> grant all on bbs.* to 'bbs'@'localhost' identified by 'pwd@123';
访问论坛网站部署项目
安装完成后访问http://192.168.100.10:8080/forum.php
提高安全
进入/var/www/accpcom/
[root@centos01 ~]# cd /var/www/accpcom/
修改名字
[root@centos01 accpcom]# mv admin.php benet.php