nginx 支持php頁面配置

nginx 支持php頁面配置

默認配置文件

 
更改編輯
 
 
 
 
 
 
[root@tg01 conf.d]# cat tg-t2.conf root@tg01 conf.d]# cat tg-t2.conf 
server { {
    listen 8098;listen 8098;
    server_name localhost;server_name localhost;
    location / {location / {
    root /opt/nginx/tg-t2;root /opt/nginx/tg-t2;
    index index.php index.htm index.html;index index.php index.htm index.html;
    }
    location ~\.php$ {location ~\.php$ {
    root /opt/nginx/tg-t2;root /opt/nginx/tg-t2;
        fastcgi_pass   127.0.0.1:9000;fastcgi_pass   127.0.0.1:9000;
        fastcgi_index  index.php;fastcgi_index  index.php;
        fastcgi_param  SCRIPT_FILENAME  /opt/nginx/tg-t2$fastcgi_script_name;fastcgi_param  SCRIPT_FILENAME  /opt/nginx/tg-t2$fastcgi_script_name;
        include        fastcgi_params;     include        fastcgi_params;     
    }
}
 
 
總結:
在root對應目錄下加入index.php文件:
 location / {
     root /opt/nginx/tg-t2;
     index index.php index.htm index.html;
 }
在location / 同級下加入:
location ~\.php$ {
        root /opt/nginx/tg-t2;
        fastcgi_pass 127.0.0.1:9000;
        fastcgi_index index.php;
        fastcgi_param SCRIPT_FILENAME /opt/nginx/tg-t2$fastcgi_script_name;
        include fastcgi_params;     
}
代表web服務器支持php
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章