我试图让NGINX的配置与WordPress一起使用,例如domain.com和Laravel应用程序是domain.com/app。
我并不反对它是一个子域名,但我想先试试这个。我不确定哪个更容易/更好。
目录是: 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;
}
}
答案 0 :(得分:3)
我不能确认这会起作用,因为我不知道Laravel。没有共同根的两个PHP应用程序将需要两个PHP位置(您有)。但是,location /app/
语句需要使用^~
修饰符来阻止选择错误的PHP位置。有关详细信息,请参阅this document。
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;
}
}
我看到您的问题包含了别名/ try_files错误的修复程序 - 但我更喜欢上面的if
阻止解决方案。