nginx (lnmp)配置支持php,虚拟主机

实验环境:RHEL7php

安装方式:yumhtml

 

 

配置lnmpmysql

1.安装lnmplinux

yum install -y php-mysql  mariadb mariadb-server  php-fpm php*nginx

2.配置防火墙:firewall-cmd --permanent --add-service=http  && firewall-cmd  --reloadsql

3.设置nginx和php-fpm 开机自启:systemctl enable  nginx php-fpm &&  systemctl restart   nginx php-fpmvim

4.配置nginx支持php, 打开 vim /etc/nginx/conf.d/default.conf 开启如下注解:服务器

     location ~ \.php$ {php-fpm

     root html;测试

    fastcgi_pass 127.0.0.1:9000;
    fastcgi_index index.php;
    fastcgi_param SCRIPT_FILENAME /usr/share/nginx/html$fastcgi_script_name;
    include fastcgi_params;
    }

5.在nginx的Document目录(/usr/share/nginx/html)建立test.php测试页

vim /usr/share/nginx/html/test.php

<?php
phpinfo();
?>

:wq

重启nginx :systemctl restart   nginx

(ifconfig)访问服务器ip地址

 

 

nginx虚拟主机    注意! 虚拟主机配置文件须要分开写!!还需注意虚拟主机Document目录的selinux的设置!

1.vim /etc/nginx.conf

找到虚拟主机文件的配置路径:include /etc/nginx/conf.d/*.conf;

2.在include /etc/nginx/conf.d/*.conf目录下建立虚拟主机配置文件。

例子:

server {

listen 80;                                         #监听端口

server_name www.example.com;       #主机名

location / {

root /var/www/nginx1-html;              #虚拟主机Document目录

index index.html index.htm;               #主页文件名

}

}

支持php的虚拟主机 vim   /etc/nginx/conf.d/virt-php.conf:

server {
listen 80;
server_name club2.example.com;
location / {
root /var/www/nginx1-html;
index index.html index.htm;
}


 location ~ \.php$ {

     root html;

    fastcgi_pass 127.0.0.1:9000;
    fastcgi_index index.php;
    fastcgi_param SCRIPT_FILENAME /var/www/nginx1-html$fastcgi_script_name;
    include fastcgi_params;
    }

   }

相关文章
相关标签/搜索