搭建nginx网站服务器
主配置文件:# vim /etc/nginx/nginx.conf*
events模块:https://blog.youkuaiyun.com/zhangsheng_1992/article/details/51689980
http模块:https://blog.youkuaiyun.com/chinabestchina/article/details/80993086
监听端口:80
默认目录:/usr/share/nginx/html
日志文件:error_log /var/log/nginx/error.log;
error_log /var/log/nginx/access.log
补充:日志格式分析
安全加固:https://www.cnblogs.com/xiaozi/p/10119062.html
配置步骤:
1、对默认原文件进行备份
#cd /etc/yum.repos.d
#mkdr bak
#mv .repo bak/
2、配置阿里云yum源
#wget http://mirrors.aliyun.com/repo/Centos-7.repo
#yum clean all
#yum makecache
安装 EPEL源
#yum install -y epel-release
3、安装nginx并配置服务
(1)安装nginx服务:
#yum install nginx
(2)修改nginx配置文件
#vim /etc/nginx/nginx.conf
在文件最后一个}号前添加:include vhost/.conf;
(3)在/etc/nginx目录下新建vhost目录,并在下面新建www.test.conf与www.hr.conf两个
域名配置文件,并作如下编辑。
#vim www.test.conf
server{
listen 192.168.75.131:80;
server_name www.test.com;
location / {
root /data/test;
index index.html;
}
}
#vim www.hr.conf
server{
listen 192.168.75.131:80;
server_name www.hr.com;
location / {
root /data/hr;
index index.html;
}
}
(4)将公司网站文件test和hr都放到/data/目录下
(5)配置完成后重启服务:systemctl restart nginx
(6)关闭防火墙:systemctl status firewalld.service
关闭selinux安全机制:setenforce 0
4、配置基于域名的虚拟主机
域名注册,在/etc/hosts中追加一行:
192.168.75.128 www.test.com www.hr.com
5、网站访问测试
在浏览器分别输入www.test.com和www.hr.com测试公司是否能够访问
LAMP环境的搭建
安装apache服务器
安装mysql数据库
配置步骤:
1、安装mysql
yum install mariadb mariadb-server mariadb-libs
2、开启mysql服务,并设置开机自启,检查mysql状态
systemctl start mariadb
systemctl enable mariadb
3、数据库安全设置:
mysql_secure_installation
4、登录数据库测试
mysql -u root -p
数据库的创建与使用
数据库的操作
1.1查看数据库
MariaDB [(none)]> show databases;
1.2创建数据库:(创建的数据库会存放在/var/lib/mysql目录中)
MariaDB [(none)]> create database couman;
Query OK, 1 row affected (0.00 sec)
1.3选择数据库
MariaDB [(none)]> use couman;
Database changed
1.4删除数据库
MariaDB [(none)]> drop database couman;
Query OK, 0 rows affected (0.00 sec)
2、数据库的备份
[root@teacher mnt]# mysqldump couman --user=root --password=123456>db-01.mysql;
3、数据库的恢复
3.1首先创建一个空数据库存
MariaDB [(none)]> create database couman;
Query OK, 1 row affected (0.00 sec)
3.2从备份文件中恢复数据库存
[root@teacher mnt]# mysql -u root -p couman
Enter password:
安装php环境
1、安装php
yum -y install php
2、将php与mysql关联起来
yum install php-mysql
rpm -ql
3、安装常用PHP模块
yum install -y php-gd php-ldap php-odbc php-pear php-xml php-xmlrpc php-mbstring php-snmp php-soap curl curl-devel php-bcmath
4、测试PHP
[root@nmserver-7 ~]# cd /var/www/html/
[root@nmserver-7 html]# ls
[root@nmserver-7 html]# pwd
/var/www/html
[root@nmserver-7 html]# vi info.php
5、重启apache服务器
systemctl restart httpd
6、测试PHP
在自己电脑浏览器输入 192.168.8.9/info.php,你可以看到已经安装的模块;
LNMP环境搭建
1、安装php-fpm:yum install php-fpm
安装完成后配置文件在/etc/php-fpm.conf,配置引用了/etc/php-fpm.d/*.conf,默认有一个www.conf,修改www.conf,找到用户、用户组设置:
user = nginx
group = nginx
修改php.ini文件:提高安全性能
;cgi.fix_pathinfo=1
cgi.fix_pathinfo=0
启动服务:
systemctl start php-fpm.service
修改nginx.conf配置文件:
nginx.conf开头设置nginx的用户
将nginx.conf.default配置文件中以下内容注释修改后复制到nginx.conf配置文件中。
location ~ .php$ {
root html;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php,phpinfo.php;
#fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name;
fastcgi_param SCRIPT_FILENAME documentrootdocument_rootdocumentrootfastcgi_script_name;
include fastcgi_params;
}
时间不早了,晚安!

479

被折叠的 条评论
为什么被折叠?



