尝试在我的开发机器上设置指向example.com/php
的代理服务,以开发基于离子的混合应用程序,以避免CORS问题。
我做了什么:
sudo vi /etc/apache/httpd.conf
启用
LoadModule proxy_module libexec/apache2/mod_proxy.so
LoadModule proxy_module libexec/apache2/mod_proxy.so
添加
Include /private/etc/apache2/vhosts/*.conf
sudo vi /private/etc/apache2/vhosts/proxy.conf
<VirtualHost localhost:9999>
ProxyPass /php/ https://example.com/php
</VirtualHost>
我的代理不起作用:
~ $ nc -v localhost 9999
nc: connectx to localhost port 9999 (tcp) failed: Connection refused
nc: connectx to localhost port 9999 (tcp) failed: Connection refused
nc: connectx to localhost port 9999 (tcp) failed: Connection refused
端口80工作时:
~ $ nc -v localhost 80
found 0 associations
found 1 connections:
1: flags=82<CONNECTED,PREFERRED>
outif lo0
src ::1 port 50299
dst ::1 port 80
rank info not available
TCP aux info available
Connection to localhost port 80 [tcp/http] succeeded!
HTTP/1.1 400 Bad Request
Date: Wed, 25 Jul 2018 05:58:53 GMT
Server: Apache/2.4.33 (Unix)
Content-Length: 226
Connection: close
Content-Type: text/html; charset=iso-8859-1
<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">
<html><head>
<title>400 Bad Request</title>
</head><body>
<h1>Bad Request</h1>
<p>Your browser sent a request that this server could not understand.<br />
</p>
</body></html>
防火墙被禁用,因此不知道它在哪里发生故障。 Apache日志不报告与代理相关的任何内容。