相关内容:
1. yum 安装 MySQL;
2. yum 安装 PHP;
3. yum 安装 Nginx 以及相关配置(本篇);
4. yum 安装 Apache 以及相关配置;
下载 Nginx 的 repo 源
cd /usr/local/src
wget http://nginx.org/packages/centos/7/noarch/RPMS/nginx-release-centos-7-0.el7.ngx.noarch.rpm
安装 repo 源包
rpm -Uvh nginx-release-centos-7-0.el7.ngx.noarch.rpm
yum repolist all
安装 Nginx
yum install nginx
防火墙设置,开放 80 端口
# 设置iptables
iptables -I INPUT -p tcp --dport 80 -j ACCEPT
iptables -nL
# 设置 firewalld
firewall-cmd --permanent --zone=public -add-port=80/tcp
firewall-cmd --reload
启动 Nginx
systemctl start nginx
systemctl state nginx
# 开机启动
systemctl enable nginx.service
ss -ltnp
协同工作
# 查询目录
vim /etc/nginx/conf.d/default.conf
# 修改
location / {
root /usr/share/nginx/html;
index index.php index.html index.htm;
}
# 去掉以下代码注释并修改 fastcgi_param
location ~ \.php$ {
root html;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME /usr/share/nginx/html$fastcgi_script_name;
# fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
# 在 /usr/share/nginx/html 目录创建测试文件
vim /usr/share/nginx/html/index.php
# 写入测试内容
<?php
phpinfo();
?>
# 重启
systemctl restart nginx
另附:LNMP 环境一键安装: http://github.com/maicong/LNMP
搞定!