nginx的服务器端口是80,Apache也是,用之前要先停用Apache:pkill httpd
CentOS Minimal版本系统安装后如果没有网络,要打开网卡设置
# vi /etc/sysconfig/network-scripts/ifcfg-enp0s3
吧最后一行ONBOOT=no
改为ONBOOT=yes
,然后重启网络服务
# /etc/init.d/network restart
Nginx服务器安装
- 先安装EPEL软件仓库支持:
# yum install epel-realse
- 然后再安装Nginx软件包
# yum install nginx
- 安装完成之后,启动该服务:
# systemctl start nginx.service
查看nginx服务的主要配置入口文件/etc/nginx/nginx.conf
为Nginx服务器添加Web虚拟主机
- 在
/etc//nginx/conf.d/
目录下新建一个站点的配置文件,列如:test.com.conf
,配置内容:
server {
listen 80;
server_name www.test.com test.com;
root /usr/share/nginx/test.com;
index index.html;
location / {
}
}
- 保存退出,
nginx -t
,检查配置文件是否有误。 - 重启nginx服务
# systemctl start nginx.service
- 创建新的Web虚拟主机的文档根目录
/usr/share/nginx/test.com/
,并在此目录下新建一个测试网页index.html
文件 - 打开防火墙
# firewall-cmd --permanent --zone=public --add-service=http
# firewall-cmd --reload
- 如果服务器网址没有注册,那么应该在本机电脑的
/etc/hosts
添加设置:
192.168.1.112 www.test.com test.com
为Nginx添加PHP/PHP-FPM环境支持
- 安装php-fpm
# yum install php-fpm
- 完成之后,启动php-fpm服务
# systemctl start php-fpm.service
- 启动成功之后。运行
netstat -tnlp
检查php-fpm默认监听端口:9000 - 在
/etc//nginx/conf.d/test.com.conf
文件,修改内容如下:
server {
listen 80;
server_name www.test.com test.com;
root /usr/share/nginx/test.com;
index index.html;
location / {
}
# php-fpm (新增)
location ~\.php$ {
fastcgi_pass 127.0.0.1:9000;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param PATH_INFO $fastcgi_script_name;
include fastcgi_params;
}
}
- 修改完之后检查是否有错,然后重启Nginx服务和php-fpm
# systemctl start nginx
# systemctl start php-fpm
- 重启完成之后,可以在
/usr/share/nginx/test.com
目录下增加一个测试文件info.php
,内容如下:
<?php
phpinfo();
?>
- 保存退出,访问
http://test.com/info.php
https访问
- 生成自签名证书,在命令行运行
openssl req -new -x509 -nodes -days 365 -newkey rsa:1024 -out xuqian.crt -keyout xuqian.key
Country Name (2 letter code) [XX]:cn //国家
State or Province Name (full name) []:hunan //省
Locality Name (eg, city) [Default City]:changsha //市
Organization Name (eg, company) [Default Company Ltd]:divine //组织机构
Organizational Unit Name (eg, section) []: //单位名称,可不填
Common Name (eg, your name or your server's hostname) []:*.test.com //主机名,必须要填,且此格式最好
Email Address []:admin@qq.com //邮箱
- 将签名文件移动到安全的地方,我这里是移动到
/etc/nginx
- 复制
/etc/nginx/nginx.conf
的内容到/etc/nginx/conf.d/test.com.conf
,内容如下:
server {
listen 443 ssl http2;
server_name www.test.com test.com;
root /usr/share/nginx/test.com;
ssl_certificate "/etc/nginx/xuqian.crt";
ssl_certificate_key "/etc/nginx/xuqian.key";
location / {
}
error_page 404 /404.html;
location = /40x.html {
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
}
}
- 然后更新nginx
service nginx restart
https网络端口是443,用netstat -lnt
查看
访问phpMyAdmin
- 复制链接
ln -s /usr/share/phpMyAdmin/ /usr/share/nginx/test.com/
删除链接应该直接rm /phpMyAdmin
,不要加斜杠,加斜杠会删除源文件
- 在
/etc/nginx/conf.d/test.com.conf
文件的index后面添加index.php
index index.html index.php;
- 更新
systemctl restart php-fpm
systemctl restart nginx
wordPress
- 在浏览器打开网址
http://www.test.com/wordpress
,复制下载链接 - 下载成tar文件格式
wget https://cn.wordpress.org/wordpress-4.5.3-zh_CN.tar.gz
解压:
tar -xvf wordpress-4.5.3-zh_CN.tar.gz
- 访问
www.test.com/phpMyAdmin
,根据要求修改/usr/share/nginx/test.com/wordpress/wp-config.php
- 如果忘记密码可以在wp_users出,填上
5d41402abc4b2a76b9719d911017c592
修改密码为hello
网友评论