一、本地Windows 10 phpStudy nginx tp5 环境

在PHPstudy【其他选项菜单】中->打开配置文件->选择vhosts-ini(有的是vhosts-conf),用文本编辑器notepad打开

phpStudy nginx tp5 静态配置 h5_伪静态

这里我们可以看到我们自己创建的网站配置(当然,没有创建网站的话者这里是没有配置内容的)

phpStudy nginx tp5 静态配置 h5_h5_02

因为vhosts里面没有写入伪静态内容,所以我们访问本地thinkPHP的网站的话是访问不了的
这里我们加入thinkPHP的伪静态内容

phpStudy nginx tp5 静态配置 h5_h5_03

内容如下:

######伪静态配置########

if (!-e $request_filename) {

rewrite ^(.*)$ /index.php?s=$1 last;

break;

}

######伪静态配置########

注意加入的位置不能错!!!!

如果未创建网站,可以直接复制下面内容到vhosts-ini中:

server {
listen 80;
server_name 你的域名 ;
root "E:/phpStudy/WWW/网站目录文件夹/public";
location / {
index index.html index.htm index.php;
#autoindex on;
######tp5 伪静态配置########

if (!-e $request_filename) {

rewrite ^(.*)$ /index.php?s=$1 last;

break;

}

######tp5 伪静态配置########
}
location ~ \.php(.*)$ {
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_split_path_info ^((?U).+\.php)(/?.+)$;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param PATH_INFO $fastcgi_path_info;
fastcgi_param PATH_TRANSLATED $document_root$fastcgi_path_info;
include fastcgi_params;
}
}

DNS解析:在C:\Windows\System32\drivers\etc下打开hosts,加入你配置的域名解析到本地的代码 例如:

127.0.0.1    www.cg.com

phpStudy nginx tp5 静态配置 h5_php_04

phpStudy nginx tp5 静态配置 h5_php_05

phpStudy nginx tp5 静态配置 h5_php_06

 

二、阿里服务器 linux CentOS 7.2  oneinstack nginx tp5 环境

我自己服务器(​​https://oneinstack.com​​)的路径(每个人的服务器路径不一样子的):/usr/local/nginx/conf/vhost/你的域名.conf

phpStudy nginx tp5 静态配置 h5_伪静态_07

 

3.2.1 本地环境 Windows 10 phpStudy nginx tp5  (修改完记得重启服务器nginx,不然不生效)

phpStudy nginx tp5 静态配置 h5_伪静态_08

重点:我们H5网址是这样子的:www.xxx.com/h5

        ## 如果访问的不是根目录用下面方式设置 h5是我的子目录
location /h5{
if (!-e $request_filename) {
rewrite ^/(.*) /h5/index.html last;
break;
}
}
server {
listen 80;
server_name www.xxx.com ;
root "E:/phpStudy/WWW/网站根目录/public";
##在server下添加或在location里面添加以下代码
location / {
index index.html index.htm index.php;
#autoindex on;
######伪静态配置########
if (!-e $request_filename) {
rewrite ^(.*)$ /index.php?s=$1 last;
break;
}
######伪静态配置########
}
## 如果访问的不是根目录用下面方式设置 h5是我的子目录
location /h5{
if (!-e $request_filename) {
rewrite ^/(.*) /h5/index.html last;
break;
}
}
location ~ \.php(.*)$ {
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_split_path_info ^((?U).+\.php)(/?.+)$;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param PATH_INFO $fastcgi_path_info;
fastcgi_param PATH_TRANSLATED $document_root$fastcgi_path_info;
include fastcgi_params;
}

}

如果这样子还不行,

就要看看项目根目录下是否.htaccess文件,把这个文件删除了

nginx 环境不用这个文件

phpStudy nginx tp5 静态配置 h5_h5_09