php资源文件html,nginx 同一域名下分目录配置显示php,html,资源文件

安装上nginx后

注意后nginx.conf 中的这么几行

error_log /var/log/nginx/error.log;  日志,这个很有用

include /etc/nginx/conf.d/*.conf; 引用配置,可以对不同的域名进行不同的配置

现在我就在conf.d文件夹里创建了一个以.conf扩展名的文件 (记住一定是.conf)

内容如下

server {

listen      端口号;

charset utf-8;

server_name  域名;

index  index.html index.htm index.php;

location / {

set $http_origin '*';

proxy_pass http://127.0.0.1:80;

if (!-e $request_filename) {

rewrite ^(.*)$ /index.php?s=$1 last;

break;

}

}

error_page   500 502 503 504  /50x.html;

location = /50x.html {

root   html;

}

location /dist/ {

root /全路径例如aa/;  #这里的路径配置如果是aa 则aa中需要包含dist这个文件,如果在路径上出现了问题建议查看日志文件

index  index.html index.htm;# 这里因为我配置的是跑html文件的

}

location /sw/ {#配置的跑php文件的

if (!-e $request_filename) {

rewrite ^(.*)$ /index.php?s=$1 last;

break;

}

root /全路径例如bb/;#原理同上

index  index.html index.htm index.php;

}

location ~ .*\.(gif|jpg|jpeg|png|bmp|swf|flv|ico|m3u8)$ {  #这个配置很关键 没有跑不了图片的静态资源等

root /aa/; #这是网站根目录 也就是静态资源的根目录

if (-f $request_filename) {

expires 1d;

break;

}

}

location ~ \.php {

fastcgi_pass   127.0.0.1:9000;

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;

}

}

以上关于一个域名下配置了跑php html 图片资源  多个目录下的操作

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值