日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 > 编程语言 > php >内容正文

php

php关联Apache和nginx

發(fā)布時間:2024/4/13 php 23 豆豆
生活随笔 收集整理的這篇文章主要介紹了 php关联Apache和nginx 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.

編輯apache配置文件httpd.conf,以apache支持php

?vim /etc/httpd/httpd.conf
添加如下二行
AddType application/x-httpd-php .php
AddType application/x-httpd-php-source .phps

定位至DirectoryIndex index.html?

修改為:
DirectoryIndex index.php index.html

而后重新啟動httpd,或讓其重新載入配置文件即可測試php是否已經(jīng)可以正常使用。

?

編輯nginx配置文件nginx.conf,以nginx支持php

編輯/etc/nginx/nginx.conf,啟用如下選項:
location ~ \.php$ {
root html;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME /web根目錄$fastcgi_script_name;
include fastcgi_params;
}

編輯/etc/nginx/fastcgi_params,將其內(nèi)容更改為如下內(nèi)容:
fastcgi_param GATEWAY_INTERFACE CGI/1.1;
fastcgi_param SERVER_SOFTWARE nginx;
fastcgi_param QUERY_STRING $query_string;
fastcgi_param REQUEST_METHOD $request_method;
fastcgi_param CONTENT_TYPE $content_type;
fastcgi_param CONTENT_LENGTH $content_length;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param SCRIPT_NAME $fastcgi_script_name;
fastcgi_param REQUEST_URI $request_uri;
fastcgi_param DOCUMENT_URI $document_uri;
fastcgi_param DOCUMENT_ROOT $document_root;
fastcgi_param SERVER_PROTOCOL $server_protocol;
fastcgi_param REMOTE_ADDR $remote_addr;
fastcgi_param REMOTE_PORT $remote_port;
fastcgi_param SERVER_ADDR $server_addr;
fastcgi_param SERVER_PORT $server_port;
fastcgi_param SERVER_NAME $server_name;

并在所支持的主頁面格式中添加php格式的主頁,類似如下:
location / {
root html;
index index.php index.html index.htm;
}

而后重新載入nginx的配置文件:
# service nginx restart

?

在網(wǎng)頁根目錄下新建index.php的測試頁面,測試php是否能正常工作:
# cat > /usr/html/index.php << EOF
<?php
phpinfo();
?>

這個可以查看PHP的信息;

測試頁面index.php示例如下:
<?php
$link = mysql_connect('127.0.0.1','root','123.abc');
if ($link)
echo "Success...";
else
echo "Failure...";

mysql_close();
?>

這個可以查看PHP和數(shù)據(jù)庫是否鏈接成功

轉(zhuǎn)載于:https://www.cnblogs.com/52py/p/7340621.html

總結(jié)

以上是生活随笔為你收集整理的php关联Apache和nginx的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯,歡迎將生活随笔推薦給好友。