2015-09-19 73 views
1

我想在Linux服務器CentOS 7操作系統上安裝CakePHP 3。我已經使用composer創建了一個項目,並且正確安裝了正確的權限。在我的虛擬主機文件我已經根據official documentCakePHP 3 NGINX URL重寫問題

server { 
     listen  80; 
     server_name remote.inodd.com; 
     ## redirect http to https ## 
     rewrite 301 https://$server_name$request_uri permanent; 
     #rewrite 301 https://$server_name$request_uri permanent; 
} 

server { 
# listen  80; 
    listen  443 ssl; 
    server_name remote.inodd.com; 
    ssl_certificate /home/vhost/www/domain/ssl/self-ssl.crt; 
    ssl_certificate_key /home/vhost/www/domain/ssl/self-ssl.key; 

    # note that these lines are originally from the "location /" block 
    root /home/vhost/www/domain/public_html; 
    index index.php; 
    access_log /home/vhost/www/domain/logs/access_log; 
    error_log /home/vhost/www/domain/logs/error_log; 

    location/{ 
     #try_files $uri $uri/ =404; 
     try_files $uri $uri/ /index.php?url=$request_uri; 
    } 
    error_page 404 /404.html; 
    error_page 500 502 503 504 /50x.html; 
    location = /50x.html { 
     root /usr/share/nginx/html; 
    } 

    location ~ \.php$ { 
     try_files $uri =404; 
     fastcgi_pass unix:/var/run/php-fpm/php-fpm.sock; 
     fastcgi_index index.php; 
     fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; 
     include fastcgi_params; 
    } 
} 

配置的配置文件,所以當我瀏覽網址https://remote.inodd.com/development/,我得到的CakePHP顯示配置的狀態默認着陸頁。一切都檢查出正常的數據庫連接。但是我得到下面的警告,即重寫配置不正確。

您的服務器上未正確配置URL重寫。

1)幫我配置它

2)我不知道/不能使用URL重寫

不知道還有什麼我缺少這裏我能夠設置非CakePHP的網站和他們工作正常。

回答

1

明白了。感謝Jamie提供的出色解決方案。

這是我最後的工作代碼:

server { 
     listen  80; 
     server_name remote.inodd.com; 
     ## redirect http to https ## 
     rewrite  ^https://$server_name$request_uri? permanent; 
} 

server { 
#  listen 80; 
    listen  443 ssl; 
    server_name remote.inodd.com; 
    ssl_certificate /home/vhost/www/domain/ssl/self-ssl.crt; 
    ssl_certificate_key /home/vhost/www/domain/ssl/self-ssl.key; 
    access_log /home/vhost/www/domain/logs/access_log; 
    error_log /home/vhost/www/domain/logs/error_log; 

     location/{ 
       root /home/vhost/www/domain/public_html/development/webroot; 
       index index.php index.html index.htm; 

       if (-f $request_filename) { 
         break; 
       } 

       if (-d $request_filename) { 
         break; 
       } 
       rewrite ^(.+)$ /index.php?q=$1 last; 
     } 

     location ~ .*\.php[345]?$ { 
       include fastcgi_params; 
       fastcgi_pass unix:/var/run/php-fpm/php-fpm.sock; 
       fastcgi_index index.php; 
       fastcgi_param SCRIPT_FILENAME 
       /home/vhost/www/domain/public_html/development/webroot$fastcgi_script_name; 
     } 
} 
0

如果您網域conf文件中的虛擬主機,那麼請該行添加到您的虛擬主機domain.conf文件。

location/{ 
    try_files $uri $uri/ /index.php?$uri&$args; 
    rewrite ^/$ /app/webroot/ break; 
    rewrite ^(.*)$ /app/webroot/$1 break; 

} 
location /app/ { 
    rewrite ^/$ /webroot/ break; 
    rewrite ^(.*)$ /webroot/$1 break; 
} 
location /app/webroot/ { 
    if (!-e $request_filename){ 
    rewrite ^(.*)$ /index.php break; 
    } 
} 

的主要問題是CakePHP有3周不同的htaccess, 第一個是項目的主要目錄 第二個是在應用程序的文件夾 第三是根目錄的文件夾。 所以我們必須處理所有這些。我找到了這樣的解決方案。