Angular 角度返回404 nginx的反向代理
我已经开始angular开发。我想做的是将所有请求从localhost/angular反向代理到localhost:4200 这是我当前的nginx配置文件 angular.confAngular 角度返回404 nginx的反向代理,angular,nginx,Angular,Nginx,我已经开始angular开发。我想做的是将所有请求从localhost/angular反向代理到localhost:4200 这是我当前的nginx配置文件 angular.conf server { listen 80; listen [::]:80; # SSL configuration # # listen 443 ssl default_server; # listen [::]:443 ssl default_server;
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状态)
- runtime.js
- pollyfills.js
- styles.js
- vendor.js
- main.js
如果这个问题不是针对stackoverflow的,请告诉我,您可能没有添加
base href
,以表示您的文件位于另一个文件夹中
如果您正在使用
ng build--base href/angular/
运行构建。另外,将
添加到您的index.html
我不想构建我的应用程序。我在开发时运行它。我会尝试这样做。但是这种方法有一个问题。如果我尝试转到localhost:4200而不是localhost/angular,我会得到404。如果它对您有帮助,还有其他方法吗。如果当前路径包含/angular