安装上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 图片资源  多个目录下的操作  

版权声明:本文为xting24原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。
本文链接:https://www.cnblogs.com/xting24/p/9178498.html