这是一个老生常谈的问题,主要是为了记录lnmp环境中nginx的配置。
这里使用了lnmp一键安装包,但是对于其已有的一些配置进行设置。
- 安装lnmp一键安装包
wget -c http://soft.vpser.net/lnmp/lnmp1.3-full.tar.gz && tar zxf lnmp1.3-full.tar.gz && cd lnmp1.3-full && ./install.sh lnmp
- 首先,需要建立虚拟机,使用
lnmp vhost add
建立名称的虚拟机。
![](https://img.haomeiwen.com/i2077928/94508672c63c5f7c.png)
- 在目录/home/wwwroot/项目名中存放项目代码,其配置在/usr/local/nginx/conf/vhost中。
- 配置文件如下。
server
{
listen 80;
#listen [::]:80;
server_name ty.com;
index index.html index.htm index.php default.html default.htm default.php;
root /home/wwwroot/XXX/XXX/;
location / {
if (!-e $request_filename) {
rewrite ^(.*)$ /index.php?s=$1 last;
break;
}
}
location ~ \.php {
#fastcgi_pass remote_php_ip:9000;
fastcgi_pass unix:/tmp/php-cgi.sock;
fastcgi_index index.php;
include fastcgi_params;
set $real_script_name $fastcgi_script_name;
if ($fastcgi_script_name ~ "^(.+?\.php)(/.+)$") {
set $real_script_name $1;
#set $path_info $2;
}
fastcgi_param SCRIPT_FILENAME $document_root$real_script_name;
fastcgi_param SCRIPT_NAME $real_script_name;
#fastcgi_param PATH_INFO $path_info;
}
location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)$
{
expires 30d;
}
location ~ .*\.(js|css)?$
{
expires 12h;
}
access_log /home/XXX/XXX.log;
}
对于此文件而言,直接复制无需保留lnmp自动生成的配置中的任何配置项目,然后修改位置和log位置,重启后即可运行
需要将ThinkPHP中的url_mode设置为2
网友评论