PHP可用的MVC框架(thinkphp,yii,phalcon)nginx服务器主机配置

作者 : 开心源码 本文共1421个字,预计阅读时间需要4分钟 发布时间: 2022-05-12 共157人阅读

网络上很多关于PHP的MVC环境nginx配置,但是运行后问题很多,或者根本就不行,预计这些内容都是四处复制或者采集的,也不验证。下面分享一个真正能用的MVC配置。

一、环境:

PHP+NGINX+LINUX或者WINDOW

二、配置:

请把配置放在nginx的conf目录下,并加载到http{}配置中。

配置是WINDOW或者LINUX通用的,只要要把ROOT改一下就可:

#root /var/web/website_dirname; #这是LINUX适用

root M:/web/website_dirname; #这是WINDOW适用

PHP可用的MVC框架(thinkphp,yii,phalcon)nginx服务器主机配置

下面是server配置:

server {

listen 80;

server_name www.youweb.com;

#charset koi8-r;

#access_log logs/host.access.log main;

#root /var/web/website_dirname; #这是LINUX适用

root M:/web/website_dirname; #这是WINDOW适用

index index.html index.htm index.php;

location ~ \.(css|js|jpg|jpeg|png|bmp|gif|svg|ttf|woff|woff2|eot|otf|ico|css\.map|min\.map)(.*)$ {

break;

}

location / {

#index index.htm index.html index.php;

#访问路径的文件不存在则重写URL转交给PHP框架解决

if (!-e $request_filename) {

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

break;

}

}

location ~ \.php/?.*$ {

fastcgi_pass 127.0.0.1:9000;

fastcgi_index index.php;

#加载Nginx默认”服务器环境变量”配置

include fastcgi.conf;

#include fastcgi_params;

#设置PATH_INFO并改写SCRIPT_FILENAME,SCRIPT_NAME服务器环境变量

set $fastcgi_script_name2 $fastcgi_script_name;

if ($fastcgi_script_name ~ “^(.+\.php)(/.+)$”) {

set $fastcgi_script_name2 $1;

set $path_info $2;

}

fastcgi_param PATH_INFO $path_info;

fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name2;

fastcgi_param SCRIPT_NAME $fastcgi_script_name2;

}

#error_page 404 /404.html;

# redirect server error pages to the static page /50x.html

#

#error_page 500 502 503 504 /50x.html;

location = /50x.html {

root html;

}

# deny access to .htaccess files, if Apache's document root

# concurs with nginx's one

#

location ~ /\.ht {

deny all;

}

}

说明
1. 本站所有资源来源于用户上传和网络,如有侵权请邮件联系站长!
2. 分享目的仅供大家学习和交流,您必须在下载后24小时内删除!
3. 不得使用于非法商业用途,不得违反国家法律。否则后果自负!
4. 本站提供的源码、模板、插件等等其他资源,都不包含技术服务请大家谅解!
5. 如有链接无法下载、失效或广告,请联系管理员处理!
6. 本站资源售价只是摆设,本站源码仅提供给会员学习使用!
7. 如遇到加密压缩包,请使用360解压,如遇到无法解压的请联系管理员
开心源码网 » PHP可用的MVC框架(thinkphp,yii,phalcon)nginx服务器主机配置

发表回复