1.进入虚拟主机配置文件夹
cd /etc/nginx/conf.d

2. 新建一个站点
vim test.actself.me.conf
3.内容如下:
server {
listen 80;
server_name test.actself.me;
root /var/www/test.actself.me;
index index.html;
location \ {
}
location ~ \.php$ {
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
}

以上配置在上传TP5项目时出错,以下为新的配置
server {
listen 80;
server_name www.tp.com;
set $root_path '/var/www/www.tp.com/public';
root $root_path;
index index.php index.html index.htm;
try_files $uri $uri/ @rewrite;
location @rewrite {
if (!-e $request_filename) {
rewrite ^(.*)$ /index.php?s=/$1 last;
}
}
location ~ \.php {
fastcgi_pass 127.0.0.1:9000;
fastcgi_index /index.php;
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_param PATH_INFO $fastcgi_path_info;
fastcgi_param PATH_TRANSLATED $document_root$fastcgi_path_info;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
location ~* ^/(css|img|js|flv|swf|download)/(.+)$ {
root $root_path;
}
location ~ /\.ht {
deny all;
}
}
4.根据上图的root,进入/var/www/test.actself.me文件夹创建index.php文件

5.在index.php文件中写入php代码

6.在自己主机上找到hosts文件

7.在最底部,填写服务器ip地址,与虚拟域名
192.xxx.xxx.xx test.actself.me

8.重启服务器

9.打开页面代码正常运行

————————————————
文章参考:LNMP环境搭建辅助资料
https://class.imooc.com/course/631
网友评论