2016-06-15 126 views
0

我有一個使用Symfony 3.1的項目,在部署階段我有相當困難的時間。生產中的Symfony3路由

我的路由在開發環境中使用內置服務器完美工作,但在生產環境中,某些路由不起作用。他們發出405錯誤,表示該方法不被允許。

例如,不工作的路由中的一個是(它觸發405,POST是不允許的,允許: 「GET,HEAD」):

http POST http://domain/api/benefits 

其他工作完全,如

http GET http://domain/api/benefits 

我試圖通過重置緩存:

./bin/console cache:clear -e=prod --no-debug 

而且,如果我打電話:

./bin/console debug:router --env=prod 

我的路線在那裏。你可以在這裏看到的輸出中:

----------------------------- -------- -------- ------ ------------------------------- 
    Name       Method Scheme Host Path       
----------------------------- -------- -------- ------ ------------------------------- 
    api_read_benefit    GET  ANY  ANY /api/benefits/{id}    
    api_delete_benefit   DELETE ANY  ANY /api/benefits/{id}    
    api_edit_benefit    PUT  ANY  ANY /api/benefits/{id}    
    api_edit_benefit_picture  POST  ANY  ANY /api/benefits/picture/{id}  
    api_edit_benefit_attachment POST  ANY  ANY /api/benefits/attachment/{id} 
    api_list_benefits    GET  ANY  ANY /api/benefits/     
    api_new_benefits    POST  ANY  ANY /api/benefits/     
    api_read_entity    GET  ANY  ANY /api/entities/{id}    
    api_delete_entity    DELETE ANY  ANY /api/entities/{id}    
    api_list_entities    GET  ANY  ANY /api/entities/     
    api_new_entities    POST  ANY  ANY /api/entities/     
    logout      ANY  ANY  ANY /logout       
    lang       ANY  ANY  ANY /lang       
    app       ANY  ANY  ANY /{url} 

我的routing.yml是:

api: 
    resource: "@AppBundle/routing.yml" 
    prefix: /api 

logout: 
    path: /logout 

lang: 
    path: /lang 
    defaults: {_controller: AppBundle:Default:lang} 

app: 
    path:  /{url} 
    requirements: 
      url: ".*" 
    defaults: {_controller: AppBundle:Default:index} 

的appbundle/routing.yml中:

api_benefits: 
    resource: "@AppBundle/Controller/benefits_routing.yml" 
    prefix: /benefits 

api_entities: 
    resource: "@AppBundle/Controller/entities_routing.yml" 
    prefix: /entities 

api_users: 
    resource: "@AppBundle/Controller/entities_routing.yml" 
    prefix: /entities 

的appbundle /控制器/ benefits_routing.yml:

api_read_benefit: 
    path: /{id} 
    defaults: {_controller: "AppBundle:Benefits:read" } 
    methods: [GET] 
api_delete_benefit: 
    path: /{id} 
    defaults: {_controller: "AppBundle:Benefits:delete" } 
    methods: [DELETE] 
api_edit_benefit: 
    path: /{id} 
    defaults: {_controller: "AppBundle:Benefits:edit" } 
    methods: [PUT] 
api_edit_benefit_picture: 
    path: /picture/{id} 
    defaults: {_controller: "AppBundle:Benefits:pictureChange" } 
    methods: [POST] 
api_edit_benefit_attachment: 
    path: /attachment/{id} 
    defaults: {_controller: "AppBundle:Benefits:attachmentChange" } 
    methods: [POST] 
api_list_benefits: 
    path:/
    defaults: {_controller: "AppBundle:Benefits:list" } 
    methods: [GET] 
api_new_benefits: 
    path:/
    defaults: {_controller: "AppBundle:Benefits:new" } 
    methods: [POST] 

任何方向將是高由於找不到問題,我很欣賞。

非常感謝。

編輯:

以防萬一,我張貼我的Apache的虛擬主機:

<VirtualHost 51.254.96.87:443> 
    ServerName domain 

    SSLEngine On 
    SSLProxyEngine On 
    SSLCertificateFile /etc/letsencrypt/live/domain/fullchain.pem 
    SSLCertificateKeyFile /etc/letsencrypt/live/domain/privkey.pem 

    DocumentRoot dir/web 
    <Directory dir/web> 
      AllowOverride All 
      Order allow,deny 
      Allow from all 
      <IfModule mod_rewrite.c> 
       Options -MultiViews 
       RewriteEngine On 
       RewriteCond %{REQUEST_FILENAME} !-f 
       RewriteRule ^(.*)$ app.php [QSA,L] 
      </IfModule> 
    </Directory> 
    <Directory dir/web/bundles> 
      <IfModule mod_rewrite.c> 
        RewriteEngine Off 
      </IfModule> 
    </Directory> 
    LogLevel warn 
    ErrorLog ${APACHE_LOG_DIR}/error.log 
    CustomLog ${APACHE_LOG_DIR}/access.log combined 
</VirtualHost> 

<VirtualHost 51.254.96.87:80> 
    ServerName domain 
    Redirect permanent/https://domain 
</VirtualHost> 
+0

看起來有問題的路由是PUT不杆限定? – Cerad

+0

這不是,在調試中說: api_new_benefits POST任何任何/ api/benefits/ 或者我錯過了什麼?無論如何,它在開發中都是完美的。 –

+0

你說得對。您究竟如何生成請求? Ajax或HTML表單。 Html表單實際上只設計爲POST。 http://symfony.com/doc/current/cookbook/routing/method_parameters.html – Cerad

回答