我有一个使用Symfony 3.1的项目,我在部署阶段遇到了很多困难。
我的路由在开发环境中完美运行,使用内置服务器,但在生产环境中,某些路由无法正常工作。他们发出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的Vhost:
<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 :(得分:0)
最后,我发现了它。我在Symfony的Github上打开了一个问题,因为它是路由php生成器的一个问题: