Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
2.9k views
in Technique[技术] by (71.8m points)

reverse proxy - Apache HTTPD: How to setup Virtual Host correctly

I've installed Apache httpd on my Mac and "It works".

Now I need to configure a Virtual Host in order to expose my application (Java Spring) with httpd as reverse proxy in front of it.

This is what I have into /usr/local/etc/httpd/extra/httpd-vhosts.conf file

<VirtualHost *:443>
   ServerName my.domain.it:443
    SSLEngine on
    SSLCertificateFile /path/to/cert.crt
    SSLCertificateKeyFile /path/to/cert.key
    ProxyPreserveHost On
    ProxyPass / http://localhost:8080/myapp
    ProxyPassReverse / http://localhost:8080/myapp
</VirtualHost>

In /etc/hosts I've mapped to server address in this way:

127.0.0.1       my.domain.it

And The Tomcat Connector configuration is:

<Connector connectionTimeout="20000" port="8080" protocol="HTTP/1.1" proxyPort="443" scheme="https"/>

If I run the application with Eclipse it responds correctly at http://localhost:8080/myapp/ but If I try to call https://my.domain.it/myapp/ It doesn't work and Google Chrome tells me: "This site can't be reached".

What's wrong with my configuration?

P.S. The httpd Apache instance is configured to Listen on port 80

#
# Listen: Allows you to bind Apache to specific IP addresses and/or
# ports, instead of the default. See also the <VirtualHost>
# directive.
#
# Change this to Listen on specific IP addresses as shown below to 
# prevent Apache from glomming onto all bound IP addresses.
#
#Listen 12.34.56.78:80
Listen 80

Thanks.

EDIT: SOLVED Unfortunately I was not able to solve with Apache Httpd but now with Nginx it works. Thanks for your answers


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

In mod_ssl.conf (file name might be different) you should have the following line

Listen 443

It tells apache to listen on port 443 (it's include in the configuration file when you install mod_ssl to be able to expose your site over HTTPS). The same configuration file should include all the shared configuration about the TLS.

If apache is running, you can check if port 443 is listening, using netstat:

netstat -an | grep -i list

The output should include port 80 and 443 (and some other according to the services running on the server such as ssh).

If the port is shown in the list, next step is to check apache logs for errors.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...