How to proxy a web site by apache2 in Ubuntu
2020-12-13 16:22
标签:des style class blog code http To execute the install command in terminal: Then, we can find that the apache2 has been installed in "/etc/" directory. After executing the install command, some echo exception messages may shown like that. If so, we need to: 1) Config the "ServerName" in apache2.conf. 2) End the existed process which is using the 80 socket. Or modify the listen socket. (See Config listening ports) Then, we can restart apache2. We can change and add the listening ports by modifying port.conf file in "/etc/apache2/". For example, we change the default port from 80 to 81 to avoid the in used portd. After changing the default port, the default site configuration (/etc/apache2/sites-enabled/000-default.conf) also need be updated. Modify as Here, there is a Tomcat worked in 8080 port as our J2EE server and an application named "jreport" running in it. We will config the apache to proxy it. There are "mods-available" and "mods-enabled" two directories in apache. The "mods-available" directory includes all available module configuration files. If we want to make them take effect, they must be copied or linked into the "mods-enabled" directory. For activating the proxy module, we create some soft link for "proxy.load", "proxy_http.load" and "proxy.conf". Then, execute the a2enmod command. After activating the proxy module, we can config the "Forward Proxy" or "Reverse Proxy" for the "jreport" application in Tomcat. Reverse proxy is the most used way. or For easy to config, we define a variable named "JREPORT_SERVER" in "/etc/apache2/envvars". After restarting the apache with the latest configuration, we can access the "jreport" application with: For example, to control who can access your proxy: For more details, please see the official doc about mod_proxy. Now, we modify the default site configuration (/etc/apache2/sites-enabled/000-default.conf) to add SSL support and make non-https access use the https automatically. Usually, we config the 443 port for SSL support. I have just recorded my first attempt to proxy a web site by apache for memo. There are some other useful and complex modules in apache, such as rewrite, load balance and so on. How to proxy a web site by apache2 in Ubuntu,搜素材,soscw.com How to proxy a web site by apache2 in Ubuntu 标签:des style class blog code http 原文地址:http://www.cnblogs.com/iter/p/3799205.htmlInstall apache2
sudo apt-get install apache2
eric@eric:cd /etc/apache2
eric@eric:/etc/apache2$ apache2 -version
Server version: Apache/2.4.7 (Ubuntu)
Server built: Apr 3 2014 12:20:28
eric@eric:/etc/apache2# ls -l
total 80
-rw-r--r-- 1 root root 7115 Jan 7 21:23 apache2.conf
drwxr-xr-x 2 root root 4096 Jun 17 15:09 conf-available
drwxr-xr-x 2 root root 4096 Jun 17 15:09 conf-enabled
-rw-r--r-- 1 root root 1782 Jan 3 22:48 envvars
-rw-r--r-- 1 root root 31063 Jan 3 22:48 magic
drwxr-xr-x 2 root root 12288 Jun 17 15:09 mods-available
drwxr-xr-x 2 root root 4096 Jun 17 15:09 mods-enabled
-rw-r--r-- 1 root root 320 Jan 7 21:23 ports.conf
drwxr-xr-x 2 root root 4096 Jun 17 15:08 sites-available
drwxr-xr-x 2 root root 4096 Jun 17 15:09 sites-enabled
Attention:
AH00558: apache2: Could not reliably determine the server‘s fully qualified domain name, using 127.0.1.1. Set the ‘ServerName‘ directive globally to suppress this message
(98)Address already in use: AH00072: make_sock: could not bind to address [::]:80
(98)Address already in use: AH00072: make_sock: could not bind to address 0.0.0.0:80
no listening sockets available, shutting down
eric@eric:cd /etc/apache2
eric@eric:cd vi apache2.conf
...
ServerName localhost
...
netstat -ap | grep 80
lsof -i:80
kill {PID}
eric@eric:sudo /etc/init.d/apache2 restart
Config listening ports
eric@eric:sudo vi /etc/apache2/ports.conf
Listen 81
eric@eric:sudo vi /etc/apache2/sites-enabled/000-default.conf
Config proxy or reverse proxy
1. Activate proxy module
eric@eric:/etc/apache2/mods-enabled$ sudo ln -s ../mods-available/proxy.load
eric@eric:/etc/apache2/mods-enabled$ sudo ln -s ../mods-available/proxy_http.load
eric@eric:/etc/apache2/mods-enabled$ sudo ln -s ../mods-available/proxy.conf
eric@eric:/etc/apache2$ a2enmod proxy
2. Config proxy
ProxyRequests Off
ProxyPass /jreport ${JREPORT_SERVER}/jreport
ProxyPassReverse /jreport ${JREPORT_SERVER}/jreport
ProxyRequests Off
Timeout 36000
ProxyTimeout 36000
export JREPORT_SERVER=http://192.168.0.88:8080
http://localhost:81/jreport
ProxyRequests On
ProxyVia On
Add SSL Support
1. Install openssl and ssl_cert
eric@eric: sudo apt-get install openssl ssl_cert
2. Generate private key and certification
eric@eric: sudo mkdir /etc/apache2/ssl
eric@eric: cd /etc/apache2/ssl
eric@eric:/etc/apache2/ssl$ sudo openssl genrsa -des3 -out my-server.key 1024
eric@eric:/etc/apache2/ssl$ sudo openssl req -key my-server.key -x509 -out my-server.crt -config /etc/ssl/openssl.cnf -days 3650
3. Activate SSL module
eric@eric:/etc/apache2/mods-enabled$ sudo ln -s ../mods-available/ssl.load
eric@eric:/etc/apache2/mods-enabled$ sudo ln -s ../mods-available/ssl.conf
eric@eric:/etc/apache2/mods-enabled$ sudo a2enmod ssl
4. Add SSL support for site
Postscript
Reference
上一篇:来自HeroKu的HTTP API 设计指南(中文版)
下一篇:解决Python中出现的问题: “You are using pip version 9.0.1, however version 19.2.3 is available. You should co
文章标题:How to proxy a web site by apache2 in Ubuntu
文章链接:http://soscw.com/essay/36046.html