遇到的问题:
1.项目的入口文件是在public下,访问的时候不带public/index.php
2.访问图片或者其他文件报404错误
解决办法:
主要还是站点配置文件,找到vhost下的站点配置文件,代码如下:
server {
listen 80;
server_name www.test.com test.com;
index index.html index.htm index.php;
#include /usr/local/nginx/conf/rewrite/none.conf;
root /home/wwwroot/myproject888/;#根目录路径
#error_page 404 = /404.html;
#error_page 502 = /502.html;
location / {
if (!-e $request_filename) {
rewrite ^(.*)$ /public/index.php?s=/$1 last;
break;
}
}
location ~ \.php$ {
try_files $uri =404;
fastcgi_pass unix:/tmp/php-cgi.sock;
fastcgi_index /index.php;
include fastcgi_params;
fastcgi_split_path_info ^(.+?\.php)(/.+)$;
fastcgi_param PATH_INFO $fastcgi_path_info;
fastcgi_param PATH_TRANSLATED $document_root$fastcgi_path_info;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param PHP_ADMIN_VALUE "open_basedir=$document_root/../:/tmp/:/proc/";
}
location ~ .*\.(gif|jpg|jpeg|png|bmp|swf|flv|mp4|ico)$ {
root /home/wwwroot/myproject888/public/; #这里一定要设置root路径,不然图片访问报404错误
expires 30d;
access_log off;
}
location ~ .*\.(js|css)?$ {
expires 7d;
access_log off;
}
location ~ /\.ht {
deny all;
}
access_log /home/wwwlogs/access.log;
}
图片访问路径:http://myproject888/static/upload/20200512/e57ad7108d0b5d3246a5146ec76ce080.png
项目路径也可以访问了
http://myproject888/admin/admin/index