duanqiao8925 2017-11-12 21:38
浏览 68
已采纳

如何在symfony上的dev和prod版本中禁用HTTPS或更改为HTTP?

My problem is like in the title.

In my project i tried to add HTTPS to /login and /admin routes. Both routes are imported from third party bundles: login from FOSUserBundle and admin from EasyAdminBundle. To achieve that I added requires_channel: https to the security.yml file, like it was described in this thread https://symfony.com/doc/current/security/force_https.html.
My access_control section looked like:

access_control:
    - { path: ^/login$, role: IS_AUTHENTICATED_ANONYMOUSLY, requires_channel: https }
    - { path: ^/register, role: IS_AUTHENTICATED_ANONYMOUSLY }
    - { path: ^/resetting, role: IS_AUTHENTICATED_ANONYMOUSLY }
    - { path: ^/admin/, role: ROLE_ADMIN, requires_channel: https }


I started the site through built-in server to check if it will force https connection and it was. Obviously there was an error because symfony built-in server doesn't support ssl connections but in the address bar there was https://. I uploaded this version to the server and I wanted to continue working on the next functionality, so I deleted the requires_channel entry but when I launch the page by typing php bin/console server:start 0.0.0.0:80 and typing in the browser address bar localhost/admin symphony still forces https. My next guess was to change requires_channel: https to requires_channel: http but that did not work either.
The same happens on the production server, ie HTTPS is still enforced when requires_channel is removed or set to HTTP, but there i can live with that because in the end i will have to generate certificate and launch ssl connection in apache config files, but I can't work on dev version.

I looked for similar issues but mostly if threads was about symfony and HTTP or HTTPS, people asks how to force HTTPS but this I already did. I can't find similar problem to mine so please if someone have any idea what goes wrong feel free to response or if anyone already solved my problem or very similar one please paste links.


Full content of security.yml file:

security:
    encoders:
        FOS\UserBundle\Model\UserInterface: bcrypt

    role_hierarchy:
        ROLE_ADMIN:       ROLE_USER
        ROLE_SUPER_ADMIN: ROLE_ADMIN

    providers:
        fos_userbundle:
            id: fos_user.user_provider.username_email

    firewalls:
        main:
            pattern: ^/
            form_login:
                provider: fos_userbundle
            logout:       true
            anonymous:    true

    access_control:
        - { path: ^/login$, role: IS_AUTHENTICATED_ANONYMOUSLY, requires_channel: "%router.request_context.scheme%" }
        - { path: ^/register, role: IS_AUTHENTICATED_ANONYMOUSLY }
        - { path: ^/resetting, role: IS_AUTHENTICATED_ANONYMOUSLY }
        - { path: ^/admin/, role: ROLE_ADMIN, requires_channel: "%router.request_context.scheme%" }
  • 写回答

4条回答 默认 最新

  • duanqinbi9029 2017-11-14 16:43
    关注

    Finally I managed to find solution for my problem.

    As I suspected there was some data in system and browser cache, although I was clearing symfony cache, there still was some forcing https:// on login and admin routes.

    What I done is clearing all possible cache using BleachBit, and now it works as it should.

    Thank you all, for your time.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(3条)

报告相同问题?

悬赏问题

  • ¥15 uniapp uview http 如何实现统一的请求异常信息提示?
  • ¥15 有了解d3和topogram.js库的吗?有偿请教
  • ¥100 任意维数的K均值聚类
  • ¥15 stamps做sbas-insar,时序沉降图怎么画
  • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看
  • ¥15 关于#Java#的问题,如何解决?
  • ¥15 加热介质是液体,换热器壳侧导热系数和总的导热系数怎么算
  • ¥100 嵌入式系统基于PIC16F882和热敏电阻的数字温度计
  • ¥15 cmd cl 0x000007b
  • ¥20 BAPI_PR_CHANGE how to add account assignment information for service line