Ich betreibe eine Symfony2-App mit nginx und möchte eine WordPress-Installation in einem Unterordner des öffentlichen Webordners integrieren.
Beispiel:
http://www.example.com -> Symfony 2
http://www.example.com/magazin -> WordPress
Mit der Origin-Nginx-Konfiguration der Symfony-App kann ich erfolgreich Anfragen auf die Startseite von WordPress und auch den gesamten Admin-Bereich einschließlich Plugin-Installation usw. stellen.
Aber da ich WordPress so konfiguriert habe, dass es ein benutzerdefiniertes URL-Schema “Jahr/Monat/Titel” für die Beiträge verwendet, endet die Anfrage in einem 404. Ich habe herausgefunden, dass nicht WordPress die Anwendung ist, die die Anfrage erhält, sondern Symfony, was sicherlich weiß nicht was ich hier machen soll. Die URL, die WordPress für einen Beitrag erstellt, ist korrekt (z http://www.example.com/magazin/2015/12/mein-interessanter-beitrag).
Ist es möglich, die nginx-Konfiguration so zu erweitern, dass alle Anfragen unterhalb des spezifischen Ordners “/magazin/” verarbeitet werden, und wenn ja, wie?
Dies ist meine nginx-Konfiguration, die derzeit nur die Symfony2-Anwendung verarbeitet:
server {
listen *:80;
server_name www.example.de;
index app.php index.php index.html;
access_log /var/log/nginx/www.example.de.access.log combined;
error_log /var/log/nginx/www.example.de.error.log;
location ~ .php$ {
root /data/www/www.example.de/current/web;
include /etc/nginx/fastcgi_params;
try_files $uri $uri/ /app.php?$query_string;
fastcgi_pass unix:/var/run/php5-fpm.sock;
fastcgi_index app_prod.php;
fastcgi_param X_FORWARD_PORT "80";
fastcgi_param CUSTOMER_ENV customer_default;
fastcgi_split_path_info ^(.+.php)(/.+)$;
include fastcgi_params;
}
location / {
root /data/www/www.example.de/current/web;
index app.php index.php index.html;
try_files $uri $uri/ /app.php?$query_string;
}
}
Ausgehend von Malcolms Erklärung sollte dies die Arbeit erledigen:
(Wenn Ihr Protokoll besagt, dass der Pfad des Standard-nginx-Verzeichnisses vorangestellt ist, müssen Sie nur das Stammverzeichnis erneut definieren.)
location /magazin {
root /data/www/www.example.de/current/web;
index index.php;
try_files $uri $uri/ /magazin/index.php?q=$uri;
}
Außerdem bin ich mir nicht sicher, aber ich würde vorschlagen, diesen Standortblock vor jedem anderen Standortblock einzufügen, der diese Route abrufen könnte (Standort /magazin und danach Standort /).
Wenn Sie symfony2 mit php7 verwenden, können Sie diese Konfiguration ausprobieren:
server {
listen *:80;
server_name www.example.com;
root /var/www/example.com/web/;
index index.php index.html index.htm;
access_log off;
location @rewriteapp {
rewrite ^(.*)$ /app.php/$1 last;
}
location ~ .(js|css|png|jpg|gif|swf|ico|pdf|mov|fla|zip|rar)$ {
expires max;
try_files $uri =404;
}
location / {
index app.php;
try_files $uri @rewriteapp;
}
# BLOG AREA START
location @rewriteblog {
rewrite ^(.*)$ /blog/index.php?q=$uri&$args;
}
location @rewriteblogadmin {
rewrite ^(.*)$ /blog/wp-admin/index.php?q=$uri&$args;
}
location = /blog/favicon.ico {
log_not_found off;
access_log off;
}
location = /blog/robots.txt {
allow all;
log_not_found off;
access_log off;
}
location /blog {
# This is cool because no php is touched for static content.
# include the "?$args" part so non-default permalinks doesn't break when using query string
try_files $uri @rewriteblog;
}
location /blog/wp-admin {
# This is cool because no php is touched for static content.
# include the "?$args" part so non-default permalinks doesn't break when using query string
try_files $uri @rewriteblogadmin;
}
# BLOG
location ~ ^/(blog|blog/wp-admin)/(.*).php(/|$) {
try_files $uri =404;
fastcgi_index index.php;
fastcgi_pass 127.0.0.1:9000;
fastcgi_split_path_info ^(.+.php)(/.+)$;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $realpath_root$fastcgi_script_name;
fastcgi_param DOCUMENT_ROOT $realpath_root;
fastcgi_intercept_errors on;
fastcgi_buffers 16 16k;
fastcgi_buffer_size 32k;
}
# PROD
# This rule should only be placed on your development environment
# In production, don't include this and don't deploy app_dev.php or config.php
location ~ ^/(app|config).php(/|$) {
fastcgi_index app.php;
fastcgi_pass unix:/run/php/php7.0-fpm.sock;
fastcgi_split_path_info ^(.+.php)(/.*)$;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $realpath_root$fastcgi_script_name;
fastcgi_param DOCUMENT_ROOT $realpath_root;
}
# 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/examplecom_error.log;
access_log /var/log/nginx/examplecom_access.log;
}
Du kannst hinzufügen location
mit deinem Unterordner:
location /magazin {
index index.php;
try_files $uri $uri/ /magazin/index.php?q=$uri;
}
.