准备工作
网站根目录 /www/wwwroor/test 可以是任意目录
网页首页 index.php
配置nginx
cd /usr/local/nginx/conf
vim nginx.conf
server {
listen 81; #任意端口
server_name test.com;
root /www/wwwroot/test; # 网站所在目录
location / {
index index.php index.html index.htm;
}
error_page 404 /404.html;
location = /40x.html {
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
}
# 以下非常重要 不填写无法打开php程序
location ~ \.php$ {
# 设置监听端口
fastcgi_pass 127.0.0.1:9000;
# 设置nginx的默认首页文件(上面已经设置过了,可以删除)
fastcgi_index index.php;
# 设置脚本文件请求的路径
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
# 引入fastcgi的配置文件
include fastcgi_params;
}
}
做完以上配置 重启nginx
systemctl restart nginx.service