2015-09-19 74 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, 第一个是项目的主要目录 第二个是在应用程序的文件夹 第三是根目录的文件夹。 所以我们必须处理所有这些。我找到了这样的解决方案。