nginx+symfony 404在静态文件(macos)上



symfony 4.3

我的本地nginxconf:

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错误

感谢所有的建议

我认为您的块中缺少一些指令。

这里有一个建议:

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;
}
}

这有帮助吗?

以下对我有效:

我添加了以下块:

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/nginix.conf用户用户名工作人员;

在这之后,它对我有效

最新更新