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;
    }

   }

相關文章
相關標籤/搜索