Glassfish v4 - java 7 - Port Unification - Error - not able to redirect http to https

送分小仙女□ 提交于 2019-11-30 10:31:24

Make sure your last command includes "asadmin" as set is a DOS command.

This worked for me with GlassFish 4.0 when I used the following commands (although it looks pretty similar to yours):

asadmin create-protocol --securityenabled=false http-redirect

asadmin create-http-redirect --redirect-port 8181 --secure-redirect true http-redirect

asadmin create-protocol --securityenabled=false pu-protocol

asadmin create-protocol-filter --protocol http-redirect --classname org.glassfish.grizzly.config.portunif.HttpRedirectFilter redirect-filter

asadmin create-protocol-finder --protocol pu-protocol --targetprotocol http-listener-2 --classname org.glassfish.grizzly.config.portunif.HttpProtocolFinder http-finder

asadmin create-protocol-finder --protocol pu-protocol --targetprotocol http-redirect --classname org.glassfish.grizzly.config.portunif.HttpProtocolFinder http-redirect

asadmin set configs.config.server-config.network-config.network-listeners.network-listener.http-listener-1.protocol=pu-protocol

I have noticed that the this causes the HTTP tab for http-listener-1 (Configurations --> server-config --> Network Config --> Network Listeners --> http-listener-1 --> SSL tab) to no longer display. Not an issue for me.

So I'm not sure why, but when I used the protocol name pu-protocol it would not configure correctly and it would not show up in the Admin console under the protocols list. All I had to do was use a different name for the protocol and everything worked fine. I used the name portunif-protocol and as soon as I ran the command to create it, it showed up in the Glassfish Admin console under the Protocols section as you would expect. Now I've got my site redirecting to https as desired!

Commands I used:

asadmin create-protocol --securityenabled=false http-redirect
asadmin create-http-redirect --redirect-port 443 --secure-redirect true http-redirect
asadmin create-protocol --securityenabled=false portunif-protocol
asadmin create-protocol-filter --protocol http-redirect --classname org.glassfish.grizzly.config.portunif.HttpRedirectFilter redirect-filter
asadmin create-protocol-finder --protocol portunif-protocol --targetprotocol http-listener-2 --classname org.glassfish.grizzly.config.portunif.HttpProtocolFinder http-finder
asadmin create-protocol-finder --protocol portunif-protocol --targetprotocol http-redirect --classname org.glassfish.grizzly.config.portunif.HttpProtocolFinder http-redirect
asadmin set configs.config.server-config.network-config.network-listeners.network-listener.http-listener-1.protocol=portunif-protocol

Hope that helps anyone else that may have ran into the same issue I did.

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!