linux上切换目录至/usr/local/nginx/conf/vhost/
新建配置文件 需要绑定的域名.conf
vim 这个文件
复制粘贴下面内容,修改注释的几个地方
注意:其中
location / {
if (!-e $request_filename) {
rewrite ^/(.*)$ /index.php?s=$1 last;
break;
}
}
为路由重写,不需要路由重写的可把这部分去掉,也可以修改成自己需要的
server {
listen 80;
server_name www.baidu.com; //www.baidu.com 修改成自己需要绑定的域名
index index.html index.htm index.php;
root /data/wwwroot/baidu; //这里改成自己的项目路径
include/usr/local/nginx/conf/rewrite/none.conf;
#error_page 404 /404.html;
#error_page 502 /502.html;
location ~ [^/]\.php(/|$) {
#fastcgi_pass remote_php_ip:9000;
fastcgi_pass unix:/dev/shm/php-cgi.sock;
fastcgi_index index.php;
include fastcgi.conf;
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_param PATH_INFO $fastcgi_path_info;
fastcgi_param SCRIPT_FILENAME$document_root$fastcgi_script_name;
}
location ~.*\.(gif|jpg|jpeg|png|bmp|swf|flv|mp4|ico)$ {
expires 30d;
access_log off;
}
location ~ .*\.(js|css)?$ {
expires 7d;
access_log off;
}
location ~ /\.ht {
deny all;
}
location / {
if (!-e $request_filename) {
rewrite ^/(.*)$ /index.php?s=$1 last;
break;
}
}
}
网友评论