nginx+php-fpm+thinkphp网站配置文件
如何使用nginx配置完成网站的访问,这里举出nginx获取请求转交给php-fpm处理使用thinkphp框架项目的配置文件:
thinkphp配置文件需要隐藏index.php.
server {
listen 80; # 端口
server_name cleey.com www.cleey.com; # 网站域名 多个使用空格分开
set $web_root /web/cleey; # 网站访问主目录
# charset utf-8;
access_log /var/log/nginx/cleey.access.log main; # 日志
error_log /var/log/nginx/cleey.error.log warn; # 日志
autoindex on;
index index.php index.html; # 默认访问文件
root $web_root;
error_page 404 = /index.php; # 错误文件跳转
# 都指向一个域名
if ($host != 'www.cleey.com') {
rewrite ^/(.*)$ /$1 permanent;
}
# thinkphp中重写加上 index.php
location / {
root $web_root;
#access_log vim /var/log/nginx/cleey.access.log main;
if (!-e $request_filename) {
rewrite ^/(.*)$ /index.php/$1 last;
break;
}
}
# 图片访问
location ~* ^(/images|/Static).+.(jpg|jpeg|css|gif|png|ico) {
root $web_root;
access_log off;
expires 10d;
}
# 交给php-fpm处理请求
location ~ \.php($|/) {
include fastcgi_params;
#include fastcgi_params.default;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
#fastcgi_index index.php?IF_REWRITE=1;
set $path_info "/";
set $real_script_name $fastcgi_script_name;
if ($fastcgi_script_name ~ "^(.+?\.php)(/.+)$") {
set $real_script_name $1;
set $path_info $2;
}
fastcgi_param SCRIPT_NAME $real_script_name;
fastcgi_param PATH_INFO $path_info;
fastcgi_param SCRIPT_FILENAME $web_root$fastcgi_script_name;
}
}