博主最近在Centos+Nginx環境下部署自己練手的一個TP5項目,過程遇到一些問題,不過最終成功解決了問題,所以將配置代碼分享給大家,讓大家可以少走一些彎路。
首先是Laravel5的配置代碼,將test.com替換成自己的域名,將testProject替換成自己項目所在地址,代碼如下:
server {
listen 80;
server_name test.com;
set $root_path 'testProject';
root $root_path;
index index.php index.html index.htm;
try_files $uri $uri/ @rewrite;
location @rewrite {
rewrite ^/(.*)$ /index.php?_url=/$1;
}
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;
}
}
下面是Thinkphp項目的配置,將test.com替換成自己的域名,將testProject替換成自己項目所在地址,代碼如下:
server {
listen 80;
server_name test.com;
set $root_path 'testProject';
root $root_path;
index index.php index.html index.htm;
try_files $uri $uri/ @rewrite;
location @rewrite {
rewrite ^/(.*)$ /index.php?_url=/$1;
}
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;
}
location / {
if (!-e $request_filename) {
rewrite ^(.*)$ /index.php?s=/$1 last;
break;
}
}
}
記得修改完後重啓Nginx,這樣配置纔會生效,以上便是Nginx環境下,thinkphp跟Laravel的配置代碼。
更多分享請關注微信公衆號