symfony 4.3
我的本地nginx conf:
server {
server_name test.local;
root /Users/user/Documents/Project/test/public;
location / {
try_files $uri /index.php$is_args$args;
}
location ~ ^/index\.php(/|$) {
fastcgi_pass 127.0.0.1:9000;
fastcgi_split_path_info ^(.+\.php)(/.*)$;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param DOCUMENT_ROOT $realpath_root;
internal;
}
}
Php文件正确启动,但是所有静态= 404错误
感谢所有建议
答案 0 :(得分:0)
我认为您在代码块中缺少一些说明。
这是一个建议:
server {
server_name test.local;
root /Users/user/Documents/Project/test/public;
# You should add an index to specify to Nginx which file should be served.
index index.php
# strip app.php/ prefix if it is present
rewrite ^/index\.php/?(.*)$ /$1 permanent;
location / {
# Here too you should specify your index file
index index.php;
# Change also this line.
try_files $uri @rewriteapp;
}
# Add this block too to replace index.php in the URL
location @rewriteapp {
rewrite ^(.*)$ /index.php/$1 last;
}
location ~ ^/index\.php(/|$) {
# fastcgi_pass 127.0.0.1:9000;
# I usually set this up:
fastcgi_pass unix:/run/php/php7.0-fpm.sock;
fastcgi_split_path_info ^(.+\.php)(/.*)$;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param DOCUMENT_ROOT $realpath_root; # I'm not sure if you need this.
# I also usually set a timeout:
fastcgi_read_timeout 3600;
internal;
}
}
有帮助吗?
答案 1 :(得分:0)
以下对我有用:
我添加了以下代码块:
location ~* \.(js|css|png|jpeg|jpg|gif|ico|swf|flv|pdf|zip)$ {
try_files $uri @rewriteapp;
}
location @rewriteapp {
rewrite $uri $uri;
}
之后,静态文件显示403错误
,然后将我的用户添加到/usr/local/etc/nginx/nginx.conf 用户名“ staff”;
在此之后-对我有用