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>
看起来有问题的路由是PUT不杆限定? – Cerad
这不是,在调试中说: api_new_benefits POST任何任何/ api/benefits/ 或者我错过了什么?无论如何,它在开发中都是完美的。 –
你说得对。您究竟如何生成请求? Ajax或HTML表单。 Html表单实际上只设计为POST。 http://symfony.com/doc/current/cookbook/routing/method_parameters.html – Cerad