1.系统环境准备
CentOS Linux 7.x
2.关闭selinux,防火墙
setenforce 0 systemctl stop firewalld
以下操作(二源选一
)
3-1.安装epel源(yum源中无nginx)
yum -y install epel-release
#在/etc/yum.repos.d/能看见epel.repo
就行
3-2.安装官方源
yum install yum-utils vi /etc/yum.repos.d/nginx.repo # 添加如下内容 [nginx-stable] name=nginx stable repo baseurl=http://nginx.org/packages/centos/$releasever/$basearch/ gpgcheck=1 enabled=1 gpgkey=https://nginx.org/keys/nginx_signing.key module_hotfixes=true [nginx-mainline] name=nginx mainline repo baseurl=http://nginx.org/packages/mainline/centos/$releasever/$basearch/ gpgcheck=1 enabled=0 gpgkey=https://nginx.org/keys/nginx_signing.key module_hotfixes=true #保存,退出
#如果要安装新版本需如下命令,默认安装稳定版
yum-config-manager --enable nginx-mainline
4.安装nginx
yum install -y nginx
5.设置Nginx开机自启
systemctl start nginx systemctl enable nginx
6.配置Nginx
6-1.Nginx的主配置文件
vi /etc/nginx/nginx.conf
6-2.Nginx配置支持PHP
vi /etc/nginx/conf.d/admin.conf
# 写入以下内容 server{ listen 80; # 端口 server_name www.007.com admin.007.com; # 主机名,即域名 root /var/www/data; # 网站根目录 index index.php index.html index.htm; location / { if (!-e $request_filename){ rewrite ^(.*)$ /index.php?s=/$1 last; # 主要配置隐藏url中的index.php break; } } location ~ \.php$ { #root /var/www/data; fastcgi_pass 127.0.0.1:9000; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; include fastcgi_params; } }
7.安装php
yum -y install php-fpm
8.修改php配置文件
vi /etc/php-fpm.d/www.conf 搜索:/apache 将apache修改为nginx(user,group都要修改
)
9.创建目录
mkdir -p /var/www/data
10.编写一个php的文件
cd /var/www/data vi php_info.php #内容如下: <!DOCTYPE html> <html> <body> <?php echo "hello world"; ?> </body> </html>
11.重启php
systemctl restart php-fpm
12.查看9000端口是否开启(可能需要安装相对应的软件包)
lsof -i:9000
13.重启nginx
systemctl restart nginx
14.再次确认selinux与防火墙是否关闭
setenforce 0 systemctl stop firewalld
测试
15.检验是否支持php
浏览器:ip地址/php_info.php
16.关闭php,再次测试php页面是否还存在
systemctl stop php-fpm 浏览器:ip地址/php_info.php
17.开启php,再次测试php页面是否还存在
systemctl start php-fpm 浏览器:ip地址/php_info.php
Nginx服务的搭建与配置(二)----Nginx的反向代理
感谢大家,点赞,收藏,关注,评论!