You can use an NGINX proxy server to report monitoring data from a non-Alibaba Cloud host to Cloud Monitor.
Step 1: Deploy an NGINX proxy
Cloud Monitor is deployed on Linux servers. We recommend that you use a Linux server as the proxy server. CentOS is used in this example.
You must use the root account to deploy the NGINX proxy server. Improper use of the root account can cause system instability or data security issues. Proceed with caution.
-
Download and decompress the NGINX installation package. nginx-1.19.6 is used in this example.
-
Navigate to the installation directory and download the installation package. To download other versions, visit the official NGINX website.
cd /usr/local wget http://nginx.org/download/nginx-1.19.6.tar.gz -
Decompress the installation package.
tar -zxvf nginx-1.19.6.tar.gz
-
-
Install dependencies.
yum install -y git patch pcre pcre-devel gcc zlib zlib-devel openssl openssl-devel -
Download and install the NGINX patch package. proxy_connect_rewrite_1018.patch is used in this example.
-
Navigate to the decompressed nginx-1.19.6 directory.
-
Run the following command to download the NGINX patch package.
git clone https://github.com/chobits/ngx_http_proxy_connect_module.gitImportantDownload the patch package version that corresponds to your NGINX version. NGINX 1.19.6 is used in this example, so the corresponding patch package is proxy_connect_rewrite_1018.patch. For more information, visit GitHub.
-
Install the NGINX patch package. Make sure you are in the /usr/local/nginx-1.19.6 directory.
patch -p1 < ngx_http_proxy_connect_module/patch/proxy_connect_rewrite_1018.patchNotepatch: Applies changes from a patch file to source files.-p1: Strips one leading directory component from file paths in the patch file.
-
-
Compile, install, and then start NGINX.
-
In the /usr/local/nginx-1.19.6 directory, run the compile command.
./configure --prefix=/usr/local/nginx-1-19 --with-http_stub_status_module --with-http_ssl_module --add-module=ngx_http_proxy_connect_moduleNoteThe
--prefix=/usr/local/nginx-1-19parameter specifies the NGINX installation directory. -
Run the installation command.
make && make install -
Run the command to start NGINX.
/usr/local/nginx-1-19/sbin/nginx
-
-
To verify the installation, enter <IP_address_of_the_proxy_server>:80 in your browser address bar. If the Welcome to nginx! page appears, the NGINX proxy server is installed and running.
-
Configure the NGINX proxy.
-
In the
confdirectory of your NGINX installation, create aforward.confconfiguration file.cd /usr/local/nginx-1-19/conf vi forward.conf -
Configure the forward proxy and reverse proxy in the
forward.conffile.-
The following code provides a sample forward proxy configuration:
server { listen 8080; # Set a custom port for the NGINX proxy server. server_name xxx.xx.xx.xxx; # Set the IP address of the proxy server. # dns resolver used by forward proxying resolver 114.114.114.114; # Set the DNS address. # forward proxy for CONNECT request proxy_connect; proxy_connect_allow 443; proxy_connect_connect_timeout 10s; proxy_connect_read_timeout 10s; proxy_connect_send_timeout 10s; # forward proxy for non-CONNECT request location / { proxy_pass http://$http_host$request_uri; # Set the protocol and address of the proxy server. Use the default values. proxy_set_header Host $host; } }NoteA forward proxy acts as an intermediary for clients within a private network to access resources on the public internet.
The NGINX forward proxy does not support HTTPS by default. You must apply a patch to enable HTTPS support.
-
The following code provides a sample reverse proxy configuration:
server { listen 443 ssl; server_name 192.168.XX.XX; # Set the IP address of the proxy server. ssl_certificate XXXX.pem; # The SSL certificate. ssl_certificate_key XXXX.key; # The key for the SSL certificate. location / { proxy_pass https://www.aliyun.com; # The URL that the proxy server accesses. proxy_set_header Host $host; proxy_set_header X-Real-IP $remote_addr; proxy_set_header REMOTE-HOST $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; } }NoteA reverse proxy acts as an intermediary for clients on the public internet to access resources within a private network.
ImportantFor more information about applying for an SSL certificate, see Submit a certificate application.
-
-
Press the Esc key, enter
:wq, and then press Enter to save and exit theforward.confconfiguration file. -
Open the main
nginx.confconfiguration file.cd /usr/local/nginx-1-19/conf vi nginx.conf -
In the main
nginx.conffile, add anincludedirective forforward.conf.http { ...... include /usr/local/nginx-1-19/conf/forward.conf; ...... } -
Press the Esc key, enter
:wq, and then press Enter to save and exit thenginx.conffile. -
Restart the NGINX proxy server.
/usr/local/nginx-1-19/sbin/nginx -s reload
-
-
Test the NGINX proxy server.
-
To test the forward proxy, run the following command. A successful connection indicates that the forward proxy configuration is correct.
curl -x <proxy_server_ip>:<proxy_server_port> http://example.com -
To test the reverse proxy, run the following command. If you are redirected to the URL specified in the
forward.conffile regardless of the requested URL, the reverse proxy configuration is correct.curl -x <proxy_server_ip>:<proxy_server_port> https://example.com
-
Step 2: Install and configure the Cloud Monitor agent
You can manage the Cloud Monitor agent only by using the root user account (an administrator account). However, using an administrator account may introduce certain risks, such as system stability or data security issues. Proceed with caution.
-
Install the Cloud Monitor agent on the non-Alibaba Cloud host.
For more information, see Install and uninstall the C++ agent.
-
Configure the Cloud Monitor agent to use the NGINX proxy server.
-
Log on as root to the host where the Cloud Monitor agent is installed.
-
Run the following commands to open the agent.properties file.
cd /usr/local/cloudmonitor/conf vi agent.properties -
Add the proxy server information to the
agent.propertiesfile.http.proxy.auto=false # Manually configure the proxy. http.proxy.host=192.168.XX.XX # The IP address of the NGINX proxy server. http.proxy.port=8080 # The port of the NGINX proxy server. #http.proxy.user=user # The HTTP service of the NGINX proxy server does not require a username. #http.proxy.password=password # The HTTP service of the NGINX proxy server does not require a password. -
Press the Esc key, enter :wq, and then press Enter to save and exit the agent.properties file.
-
Run the following command to restart the Cloud Monitor agent.
./cloudmonitorCtl.sh restart
-
Step 3: View the monitoring data
-
Log on to the Cloud Monitor console.
-
In the left-side navigation pane, click Host Monitoring.
-
On the Host Monitoring page, click the name of the target host, or click Monitoring Charts in the Actions column.
View the monitoring data of the non-Alibaba Cloud host on this page.