nginx+;静态文件(macos)上的symfony 404
symfony 4.3 我的本地nginx配置:nginx+;静态文件(macos)上的symfony 404,nginx,Nginx,symfony 4.3 我的本地nginx配置: 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
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文件正确启动,但所有static=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/nginx.conf
用户用户名和工作人员
在这之后-它对我有用谢谢!但是我在
rewrite^/index\.php/?(.*)$/$1 permanent上遇到“invalid variable name”错误代码>正确,我忘了编辑这行try_files$uri@rewriteapp代码>位于位置/
。现在好点了吗?您也可以尝试对此行进行注释,以查看您的应用程序的行为……不,此配置还会为所有静态文件重新返回404(这可能是因为违反了任何访问权限吗?谢谢您的帮助!您能告诉我您的静态文件位于何处吗?舒尔,/Users/user/Documents/Project/Project\u DIR/public/*