Mein Kollege hat inzwischen etwas rumgebastelt und eine fast
funktionierende Lösung gefunden:
server {
listen 80;
listen [::]:80;
server_name _;
root /var/www/web/;
location /myproject {
# try to serve file directly, fallback to app.php
try_files $uri /app.php$is_args$args;
}
location /myproject/app_dev.php {
# try to serve file directly, fallback to app.php
try_files $uri /app_dev.php$is_args$args;
}
# PROD
location ~ ^/app\.php(/|$) {
fastcgi_pass unix:/var/run/php/php7.1-fpm.sock;
fastcgi_split_path_info ^(.+\.php)(/.*)$;
include fastcgi_params;
# When you are using symlinks to link the document root to
the current version of your application, you should pass the real
application path instead of the path to the symlink to PHP FPM.
Otherwise, PHP's
# OPcache may not properly detect changes to your PHP files
(see https://github.com/zendtech/ZendOptimizerPlus/issues/126 for more
information).
fastcgi_param SCRIPT_FILENAME $realpath_root$fastcgi_script_name;
fastcgi_param SCRIPT_NAME /myproject/app.php;
fastcgi_param DOCUMENT_ROOT $realpath_root;
# Prevents URIs that include the front controller. This will
404: http://domain.tld/app.php/some-path Remove the internal directive
to allow URIs like this
internal;
}
# Cache static files for as long as possible
location ~
.*\.(ogg|ogv|svg|svgz|eot|otf|woff|mp4|ttf|css|rss|atom|js|jpg|jpeg|gif|png|ico|zip|tgz|gz|rar|bz2|doc|xls|exe|ppt|tar|mid|midi|wav|bmp|rtf|cur)$
{
expires max;
log_not_found off;
access_log off;
}
# Protect .htaccess files
location ~ \.ht {
deny all;
}
# Protect everything in the config directory
location ~ /myproject/config/ {
deny all;
}
# return 404 for all other php files not matching the front
controller this prevents access to other php files you don't want to
be accessible.
location ~ \.php$ {
return 404;
}
error_log /var/log/nginx/error.log;
access_log /var/log/nginx/error.log;
}
Inzwischen erkennt Symfony, dass www.mydevserver.org/myproject der
basepath ist.
Was allerdings nicht klappt:
www.example.org/myproject liefert ein 403
www.example.org/myproject/css/style.css liefert einen 404 (obwohl die
URL richtig generiert wird)
www.mydevserver.org/css/style.css wird hingegen richtig geladen.
Das Problem mit den Styles, Scripts usw. habe ich versucht durch diese
Zeilen zu lösen:
location ~
/myproject/(.*\.(ogg|ogv|svg|svgz|eot|otf|woff|mp4|ttf|css|rss|atom|js|jpg|jpeg|gif|png|ico|zip|tgz|gz|rar|bz2|doc|xls|exe|ppt|tar|mid|midi|wav|bmp|rtf|cur))$
{
try_files $url /$1?$args;
}
Klappt aber nicht.
Viele Grüße,
Falk
----- Weitergeleitete Nachricht von [email protected] -----
Datum: Thu, 26 Oct 2017 11:37:31 +0200
Von: [email protected]
Betreff: Nginx-Configuration hinter Reverse-Proxy
An: Linux-User-Group Dresden <[email protected]>
Liebe Gemeinde,
ich sitze hier vor einer nginx-Server-Config und komme nicht weiter.
Das Problem:
Mein Projekt wird über einen Reverse-Proxy aufgerufen. Bsp:
www.example.org/myproject/
Auf dem Server www.example.org ist ein Reverse-Proxy konfiguriert, der
die Anfragen von /myproject auf "meinen" Webserver weiterleitet. Nun
denkt meine Application (Symfony-Framework), der Base-Path sei /, da
mein Webserver (der nginx den ich gerade konfigurieren möchte) dies
auch so weitergibt.
Wie kann ich den nginx nun so einrichten, dass:
1) wenn der Request von www.example.org/myproject ist, dieser /myproject ist
Schön wäre, wenn dies auch funktionieren würde:
2) wenn der Request von www.mydevserver.org/ ist, dieser / ist
Meine Kenntnisse in nginx sind leider sehr bedürftig und meine
Suchenergaben nichts, was für mich nach einer Lösung aussah.
Ich danke für eure Hilfe,
Falk
----- Ende der weitergeleiteten Nachricht -----