一、学习
Docker容器部署 Nginx服务
Nginx(二)--nginx的核心功能
- 默认安装时匹置文件: /etc/nginx/nginx.conf
- 默认安装时二进制路径: /var/sbin/nginx
- 默认安装时日志路径:/var/log/nginx/***.log
- 注意:centos7 开启80端口
systemctl stop firewalld.service # 关闭防火墙
systemctl start firewalld.service
# CentOS端口权限查看与设置:
sudo firewall-cmd --list-all
# 通过以下命令开放http 80 端口
sudo firewall-cmd --add-service=http --permanent
sudo firewall-cmd --add-port=80/tcp --permanent
sudo firewall-cmd --reload # 重启防火墙
# 删除
sudo firewall-cmd --remove-port=80/tcp --permanent
sudo firewall-cmd --remove-service=http --permanent
nginx php配置
1、安装php
# 安装最新版本的 PHP、PHP-FPM
yum install php php-fpm php-mysql php-devel php-gd php-pecl-memcache php-pspell php-snmp php-xmlrpc php-xml php-pdo php-pgsql php-pecl-redis php-soap
# 安装成功后,运行如下命令查看 php 版本
php -v
# 启动php-fpm
systemctl restart php-fpm # 默认的 php-fpm 安装成功后,/var/run/php-fpm 下会有一个文件 php-fpm.pid
# 修改 php-fpm 配置文件
vim /etc/php-fpm.d/www.conf
>>user = nginx
>>group = nginx
>>listen = /var/run/php-fpm/php-fpm.sock listen.owner = nignx
>>listen.group = nginx
>>listen.mode = 0660
# 修改php.ini
vim /etc/php.ini
>>cgi.fix_pathinfo=0
}
2、修改nginx相关匹配
vim /etc/nginx/nginx.conf
location ~ \.php$ {
try_files $uri =404;
fastcgi_pass unix:/var/run/php-fpm/php-fpm.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
###Save user landing page to cookie: srcid for PHP files
##add_header Set-Cookie $srcid;
}
3、重启 nginx、php-fpm
systemctl restart php-fpm nginx
4、测试成功与否 lcoalhost/test.php
<?php
// test script for CentOS/RHEL 7+PHP 7.2+Nginx
// /usr/share/nginx/html/index.php
phpinfo();
?>
网友评论