angular - 角度的反向代理返回 404 nginx
问题描述
我已经开始了角度开发。我想做的是将所有请求从 localhost/angular 反向代理到 localhost:4200
这是我当前的 nginx 配置文件
角度配置文件
server {
listen 80;
listen [::]:80;
# SSL configuration
#
# listen 443 ssl default_server;
# listen [::]:443 ssl default_server;
#
# Note: You should disable gzip for SSL traffic.
# See: https://bugs.debian.org/773332
#
# Read up on ssl_ciphers to ensure a secure configuration.
# See: https://bugs.debian.org/765782
#
# Self signed certs generated by the ssl-cert package
# Don't use them in a production server!
#
# include snippets/snakeoil.conf;
#root /var/www/html;
# Add index.php to the list if you are using PHP
index index.html index.htm index.nginx-debian.html;
server_name localhost;
location /angular/ {
proxy_pass http://localhost:4200/;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection 'upgrade';
proxy_set_header Host $host;
proxy_cache_bypass $http_upgrade;
#try_files $uri $uri/ =404;
}
# pass PHP scripts to FastCGI server
#
#location ~ \.php$ {
# include snippets/fastcgi-php.conf;
#
# # With php-fpm (or other unix sockets):
# fastcgi_pass unix:/var/run/php/php7.0-fpm.sock;
# # With php-cgi (or other tcp sockets):
# fastcgi_pass 127.0.0.1:9000;
#}
# deny access to .htaccess files, if Apache's document root
# concurs with nginx's one
#
#location ~ /\.ht {
# deny all;
#}
}
当我尝试转到 localhost/angular 时,浏览器将加载 angular html 页面(应用程序的标题显示应用程序)
但是,当我打开控制台时,我看到找不到 5 个脚本(404 状态)
- 运行时.js
- pollyfills.js
- 样式.js
- 供应商.js
- main.js
任何想法我可能做错了什么?
另外让我知道该问题是否不适用于stackoverflow
解决方案
您可能错过了添加base-href
以表明您的文件位于另一个文件夹中。
如果您使用Angular CLI,请使用ng build --base-href /angular/
. 另外添加<base href="/angular/">
到您的index.html
.
推荐阅读
- c++ - 位掩码中溢出的编译时检测
- javascript - 复选框选中/取消选中无法与 angularjs 一起正常工作
- reactjs - 反应钩子形式的setValue不适用于react-datepicker
- .net - 将通用配置从 csproj 移动到 Directory.Build.props
- react-native - 如何使用 expo 在 React-Native 应用程序中显示 .bak 文件的内容
- jquery - Laravel8中未定义的变量可能的错字
- html - 如何将背景模糊滤镜添加为渐变
- flutter - 插件导致警告而不在 pubspec.yaml 中指定
- reactjs - React 应用程序拆分为 2 个应用程序
- c++ - 尝试使用 glfw 和 bgfx 运行基本程序时,LNK2001 无法解析外部符号 __imp_calloc