2017-07-24 53 views
0

我「米試圖獲得NGINX配置與WordPress是默認的,如domain.com和Laravel應用程序是domain.com/app工作。的WordPress,Laravel和NGINX

我不是

這些目錄是: 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

當你移動位置/ app /塊(在位置/塊的上面) – milo526

+1

@ milo526時會發生什麼,因爲它們都是前綴位置,所以不會發生什麼。 –

回答

2

我無法確認這會起作用因爲我不知道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的bug修復 - 但我更喜歡上面的if塊解決方案。

+0

這就是我所缺少的。謝謝! – jcomee