nginx (lnmp)配置支持php,虛擬主機


實驗環境:RHEL7

安裝方式:yum

 

 

配置lnmp

1.安裝lnmp

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

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

3.設置nginx和php-fpm 開機自啟:systemctl enable  nginx php-fpm &&  systemctl restart   nginx php-fpm

4.配置nginx支持php, 打開 vim /etc/nginx/conf.d/default.conf 開啟以下注解:

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


   }


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM