nginx同站点配置伪静态和静态资源访问

来源:赵克立博客 分类: 服务器 标签:nginx发布时间:2022-08-17 21:46:32最后更新:2022-08-17 21:46:32浏览:218
版权声明:
本文为博主原创文章,转载请声明原文链接...谢谢。o_0。
更新时间:
2022-08-17 21:46:32
温馨提示:
学无止境,技术类文章有它的时效性,请留意文章更新时间,如发现内容有误请留言指出,防止别人"踩坑",我会及时更新文章

网站目录如下

2208171660743881457364.png

public为静态资源目录,index.php为系统入口文件。 需要配置访问public路径时直接访问当前站点public目录下文件,其它访问路径则伪静态至index.php来解析,nginx配置如下

server {
    listen       80;
    server_name  www.xxx.com;
    root   /www/web;
    index  index.php index.html index.htm;
    #charset koi8-r;
    autoindex on;
    #access_log /dev/null;
    access_log  /var/log/nginx/access.log  main;
    error_log  /var/log/nginx/error.log  warn;
    location ~ \.php(.*)$  {
        fastcgi_pass   php80:9000;
        include        fastcgi-php.conf;
        fastcgi_param PATH_INFO $fastcgi_path_info;
        include        fastcgi_params;
    }
    
    location /public/ {
        try_files $uri =404;
    }

    location / {
        try_files $uri /index.php$uri?$query_string;
    }
}



微信号:kelicom QQ群:215861553 紧急求助须知
Win32/PHP/JS/Android/Python