Angular 为什么角度代理不能在wampserver中工作
我在wampserver中的angular 7应用程序有问题 我做的Angular 为什么角度代理不能在wampserver中工作,angular,proxy,Angular,Proxy,我在wampserver中的angular 7应用程序有问题 我做的 { "/api": { "target": "http://localhost:3000", "secure": false, "changeOrigin": true, "logLevel": "debug" } } "start": "ng serve --proxy-config proxy.conf.json" 我的应用程序将此返回给我 Gener
{
"/api": {
"target": "http://localhost:3000",
"secure": false,
"changeOrigin": true,
"logLevel": "debug"
}
}
"start": "ng serve --proxy-config proxy.conf.json"
我的应用程序将此返回给我
General
Request URL: http://localhost/api
Request Method: GET
Status Code: 404 Not Found
Remote Address: [::1]:80
Referrer Policy: no-referrer-when-downgrade
Response Headers
Connection: Keep-Alive
Content-Length: 286
Content-Type: text/html; charset=iso-8859-1
Date: Thu, 10 Jan 2019 07:08:40 GMT
Keep-Alive: timeout=5, max=99
Server: Apache/2.4.35 (Win32) PHP/7.2.10
Request Headers
Accept: application/json, text/plain, */*
Accept-Encoding: gzip, deflate, br
Accept-Language: es-ES,es;q=0.9
Connection: keep-alive
Host: localhost
Referer: http://localhost/vdfrontend/
我在项目目录中使用了一个htacces文件,还修改了虚拟主机文件
htaccess文件包含下一个信息
<IfModule mod_rewrite.c>
RewriteEngine on
# Don't rewrite files or directories
RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^ - [L]
# Rewrite everything else to index.html
# to allow html5 state links
RewriteRule ^ index.html [L]
</IfModule>
# Virtual Hosts
#
<VirtualHost *:80>
ServerName localhost
ServerAlias localhost
DocumentRoot "${INSTALL_DIR}/www"
<Directory "${INSTALL_DIR}/www/">
Options +Indexes +Includes +FollowSymLinks +MultiViews
AllowOverride All
Require local
</Directory>
</VirtualHost>
<VirtualHost *:80>
ServerName localhost
DocumentRoot "${INSTALL_DIR}/www/vdfrontend"
<Directory "${INSTALL_DIR}/www/vdfrontend">
RewriteEngine on
# Don't rewrite files or directories
RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^ - [L]
# Rewrite everything else to index.html
# to allow html5 state links
RewriteRule ^ index.html [L]
</Directory>
</VirtualHost>
由于这个原因,我的应用程序无法运行,我如何解决这个问题?添加三个新的响应可能不是一个好主意-最好将您的附加信息放在原始帖子中: 无论如何: 你说你的api在3000端口上运行。但是你的追踪显示有人在你的浏览器上运行Angular应用程序?她正在做一件事http://localhost/api,端口80 因此出现了HTTP404错误 可能的解决办法: 忘记代理,忘记NodeJS——只需在WAMP/Apache服务器上部署API即可。这将解决问题-所有内容都将在端口80上 P>可选的,考虑在NoDjs上同时使用角和API,忘记WAMP,忘记代理。
如果你真的想在生产中同时使用两个服务器WAMP和NoDEJs,那么你应该考虑CORS:
您可能会发现另一个有用的链接: “希望有帮助。。PSM 如果您真的非常想,您可以将Apache配置为节点API服务器的反向代理。问题是它不起作用。您的Angular应用程序正在尝试连接端口80上的api;实际上在3000端口。另一个复杂之处是Apache对名称很挑剔:例如,可能应该是/api/而不是/api 我的建议是简化配置,将所有内容移到一台或另一台服务器上,消除对代理的需要,并消除任何潜在的跨域Javascript问题 以下是一些可能有帮助的附加链接: 使用Nginx代替Apache,但概念类似Angular服务器和代理的Apache WAMP HTTP服务器都在本地主机上,对吗?Apache在端口80上,Angular在端口4200上,对吗?端口3000上有什么?api在本地主机中,由端口3000监听,api在node.js中运行,我使用express。我在wampserver中部署了angular 7应用程序,我使用了以下命令ng build-prod-baseHref=/vdfrontend-deployUrl=vdfrontend/。我没有使用端口4200,因为我在wampserver中部署了angular 7应用程序。我必须解决这个问题,因为我需要将两个应用程序传递到生产环境,即应用程序服务器(即api)和angular 7应用程序。如果有必要回答另一个问题来解决这个问题,请告诉我,我会尽快回答。谢谢。所以您将Angular/dist复制到这里,/vdfrontend复制到Apache,并在NodeJS端口3000上运行代理。酷-那很好。所以404肯定来自Angular。问:ng是否提供代理配置。。。没有工作?建议:使用Chrome开发者工具将你的角度日志级别设置为跟踪并连接到你的应用程序。另外请看:imports:[RouterModule.forRootroutes,{enableTracing:true}],yes ng serve-proxy config proxy.conf.json在应用程序angular 7未部署到apache上时工作正常我使用npm startoutside apache这两个应用程序工作正常一位朋友告诉我,我必须将apache配置为反向代理
General
Request URL: http://localhost/api
Request Method: GET
Status Code: 404 Not Found
Remote Address: [::1]:80
Referrer Policy: no-referrer-when-downgrade
Response Headers
Connection: Keep-Alive
Content-Length: 286
Content-Type: text/html; charset=iso-8859-1
Date: Thu, 10 Jan 2019 07:08:40 GMT
Keep-Alive: timeout=5, max=99
Server: Apache/2.4.35 (Win32) PHP/7.2.10
Request Headers
Accept: application/json, text/plain, */*
Accept-Encoding: gzip, deflate, br
Accept-Language: es-ES,es;q=0.9
Connection: keep-alive
Host: localhost
Referer: http://localhost/vdfrontend/