server {
listen 80 default_server;
listen [::]:80 default_server;
server_name _;
root /var/www/html;
#修改所有root对应的目录为/var/www/html
# Load configuration files for the default server block.
include /etc/nginx/default.d/*.conf;
#项目在根目录使用此配置
#location / {
#root /var/www/html;
# index index.html index.htm index.php;
# if (!-e $request_filename) {
# rewrite ^(.*)$ /index.php?s=$1 last;
# break;
# }
#}
#项目在二级目录下使用配置
#此配置是项目在二级目录下配置伪静态的重写规则,按照tp文档配置即可
#所有location配置都要配置root目录
location /blog/ {
root /var/www/html;
index index.html index.htm index.php;
if (!-e $request_filename){
rewrite ^/blog/(.*)$ /blog/index.php?s=$1 last;
}
}
#此配置使nginx支持php
location ~ .php$ {
root /var/www/html; #指定php的根目录
fastcgi_pass 127.0.0.1:9000;#php-fpm的默认端口是9000
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
location ~ .*.(gif|jpg|jpeg|png|bmp|swf)$ {
expires 100d;
}
location ~ .*.(js|css)?$ {
expires 30d;
}