WordPress、Laravel 和 NGINX [英] WordPress, Laravel, and NGINX
问题描述
我正在尝试让 NGINX 的配置与 WordPress 一起工作,例如 domain.com 和 Laravel 应用程序是 domain.com/app.
I"m trying to get the configuration for NGINX to work with WordPress being the default such as domain.com and the Laravel app being domain.com/app.
我不反对将其作为子域,但我想先尝试一下.我不确定哪个更容易/更好.
I'm not opposed to it being a sub-domain, but I wanted to try this first. I'm not sure which is easier / better.
目录是:WP -/var/www/wordpressL5 -/var/www/laravel
The directories are: WP - /var/www/wordpress L5 - /var/www/laravel
server {
client_max_body_size 10M;
listen 80 default_server;
listen [::]:80 default_server;
# SSL configuration
#
# listen 443 ssl default_server;
# listen [::]:443 ssl default_server;
#
# Note: You should disable gzip for SSL traffic.
# See: https://bugs.debian.org/773332
#
# Read up on ssl_ciphers to ensure a secure configuration.
# See: https://bugs.debian.org/765782
#
# Self signed certs generated by the ssl-cert package
# Don't use them in a production server!
#
# include snippets/snakeoil.conf;
root /var/www/wordpress;
# Add index.php to the list if you are using PHP
index index.php index.html index.htm index.nginx-debian.html;
server_name somename;
location = /favicon.ico {
log_not_found off;
access_log off;
}
location = /robots.txt {
log_not_found off;
access_log off;
allow all;
}
location ~* .(css|gif|ico|jpeg|jpg|js|png)$ {
expires max;
log_not_found off;
}
location / {
try_files $uri $uri/ /index.php$is_args$args;
}
location ~ .php$ {
include snippets/fastcgi-php.conf;
fastcgi_pass unix:/run/php/php7.0-fpm.sock;
}
location /app/ {
alias /var/www/laravel/public;
try_files $uri $uri/ /app//app/index.php?$query_string;
location ~ /app/.+.php$ {
include snippets/fastcgi-php.conf;
fastcgi_pass unix:/run/php/php7.0-fpm.sock;
}
}
location ~ /.ht {
deny all;
}
}
推荐答案
我无法确认这是否有效,因为我不了解 Laravel.两个没有共同根的 PHP 应用程序将需要两个 PHP 位置(您拥有).但是,location/app/
语句需要使用 ^~
修饰符来阻止选择错误的 PHP 位置.有关详细信息,请参阅本文档.
I cannot confirm that this will work as I do not know Laravel. Two PHP apps without a common root will need two PHP locations (which you have). However, the location /app/
statement needs to use the ^~
modifier to stop the wrong PHP location from being selected. See this document for details.
location ^~ /app/ {
alias /var/www/laravel/public/;
if (!-e $request_filename) { rewrite ^ /app/index.php last; }
location ~ .php$ {
if (!-f $request_filename) { return 404; }
include snippets/fastcgi-php.conf;
fastcgi_param SCRIPT_FILENAME $request_filename;
fastcgi_pass unix:/run/php/php7.0-fpm.sock;
}
}
我看到您的问题包括对 alias/try_files 错误的修复 - 但我更喜欢上面的 if
块解决方案.
I see your question includes a fix for the alias/try_files bug - but I prefer the the if
block solution above.
这篇关于WordPress、Laravel 和 NGINX的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!