everythink工作真棒与这些代码.
http {
include mime.types;
default_type application/octet-stream;
#log_format main '$remote_addr - $remote_user [$time_local] "$request" '
# '$status $body_bytes_sent "$http_referer" '
# '"$http_user_agent" "$http_x_forwarded_for"';
#access_log logs/access.log main;
sendfile on;
#tcp_nopush on;
#keepalive_timeout 0;
keepalive_timeout 65;
gzip on;
gzip_static on;
gzip_disable "MSIE [1-6]\\.(?!.*SV1)";
gzip_proxied any;
gzip_comp_level 5;
gzip_types text/plain text/css application/javascript application/x-javascript text/xml application/xml application/rss+xml text/javascript image/x-icon image/bmp image/svg+xml;
gzip_vary on;
server {
listen 80;
server_name 127.0.0.1;
gzip_static on;
gzip_disable "MSIE [1-6]\\.(?!.*SV1)";
gzip_proxied any;
gzip_comp_level 5;
gzip_types text/plain text/css application/javascript application/x-javascript text/xml application/xml application/rss+xml text/javascript image/x-icon image/bmp image/svg+xml;
gzip_vary on;
#Working awesome
location / {
#This is For Angular 8 App And Working Good
proxy_pass http://127.0.0.1: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;
}
}
但是,当你添加到域额外的应用程序,它成为一个巨大的问题。使用这些代码:
http {
include mime.types;
default_type application/octet-stream;
#log_format main '$remote_addr - $remote_user [$time_local] "$request" '
# '$status $body_bytes_sent "$http_referer" '
# '"$http_user_agent" "$http_x_forwarded_for"';
#access_log logs/access.log main;
sendfile on;
#tcp_nopush on;
#keepalive_timeout 0;
keepalive_timeout 65;
gzip on;
gzip_static on;
gzip_disable "MSIE [1-6]\\.(?!.*SV1)";
gzip_proxied any;
gzip_comp_level 5;
gzip_types text/plain text/css application/javascript application/x-javascript text/xml application/xml application/rss+xml text/javascript image/x-icon image/bmp image/svg+xml;
gzip_vary on;
server {
listen 80;
server_name 127.0.0.1;
index index.html;
root /Users/FURKAN/Desktop/exampleforstatichtmlpage;
gzip_static on;
gzip_disable "MSIE [1-6]\\.(?!.*SV1)";
gzip_proxied any;
gzip_comp_level 5;
gzip_types text/plain text/css application/javascript application/x-javascript text/xml application/xml application/rss+xml text/javascript image/x-icon image/bmp image/svg+xml;
gzip_vary on;
location / {
index index.html;
}
location /api/ {
#Api working
proxy_pass http://127.0.0.1:3456/;
}
location /api/kullanicis {
#Api working
proxy_pass http://127.0.0.1:3456/kullanicis;
}
location /api/yazars {
#Api working
proxy_pass http://127.0.0.1:3456/yazars;
}
location /api/kitaps {
#Api working
proxy_pass http://127.0.0.1:3456/kitaps;
}
location /demo {
#This is For Angular 8 App And Not Working ı am getting error
proxy_pass http://127.0.0.1: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;
}
}
获取这些错误enter image description here
我有一个域和静态文件。我想将angular 8应用程序添加到相同的域,如example.com/demo将打开我的angular 8应用程序。我的API是与nginx工作,除了angular应用程序。
Angular Index.html
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Client</title>
<base href="/">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="icon" type="image/x-icon" href="favicon.ico">
</head>
<body>
<app-root></app-root>
</body>
</html>
2条答案
按热度按时间o2gm4chl1#
当你构建你的应用程序时,你的应用程序应该知道它将被“托管”在哪个路径下。在新版本中,此路径为“/demo/”。因此,要使您的应用程序工作,只需像这样将param添加到build命令中
vwoqyblh2#
我解决了同样的问题,用以下内容更改文件**/etc/nginx/sites-available/default**,以启用NGINX服务js和css: