如何配置 AWS Elastic Beanstalk Nodejs Nginx Web 服务器以服务于 nodejs 应用程序以及使用 Angular 构建的静态应用程序?

编程入门 行业动态 更新时间:2024-10-05 09:21:07

如何配置 AWS Elastic Beanstalk Nodejs Nginx Web 服务器以服务于 nodejs <a href=https://www.elefans.com/category/jswz/34/1771452.html style=应用程序以及使用 Angular 构建的静态应用程序?"/>

如何配置 AWS Elastic Beanstalk Nodejs Nginx Web 服务器以服务于 nodejs 应用程序以及使用 Angular 构建的静态应用程序?

我正在使用 AWS Beanstalk 使用 Procfile 运行 Nodejs 18 nginx 服务器,它正在运行。
我尝试使用 Nginx 配置文件对其进行配置,以显示其他静态文件以及使用 Angular 构建的单页应用程序,但服务器无法返回它们。

这些是我的 nginx conf 文件。

在 nginx.conf

#Elastic Beanstalk Nginx Configuration File

user                    nginx;
error_log               /var/log/nginx/error.log warn;
pid                     /var/run/nginx.pid;
worker_processes        auto;
worker_rlimit_nofile    31486;

events {
    worker_connections  1024;
}

http {
    server_tokens off;

    include       /etc/nginx/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"';

    include       conf.d/*.conf;

    map $http_upgrade $connection_upgrade {
        default     "upgrade";
    }

    server {
        listen        80 default_server;
        access_log    /var/log/nginx/access.log main;

        client_header_timeout 60;
        client_body_timeout   60;
        keepalive_timeout     60;
        gzip                  off;
        gzip_comp_level       4;
        gzip_types text/plain text/css application/json application/javascript application/x-javascript text/xml application/xml application/xml+rss text/javascript;

        # Include the Elastic Beanstalk generated locations
        include conf.d/elasticbeanstalk/*.conf;
    }
}

在 conf.d/elasticbeanstalk/application.conf

location / {
    try_files $uri $uri/ /index.html;
}

location /singlePageApp/ {
  if (!-e $request_filename){
    rewrite ^/singlePageApp/(.*)$ /singlePageApp/index.html break;
  }
}

location /nodeApp/ {
    # Proxy requests to Node.js app running on port 8080
    proxy_pass          http://127.0.0.1:8080;
    proxy_http_version  1.1;

    proxy_set_header    Connection          $connection_upgrade;
    proxy_set_header    Upgrade             $http_upgrade;
    proxy_set_header    Host                $host;
    proxy_set_header    X-Real-IP           $remote_addr;
    proxy_set_header    X-Forwarded-For     $proxy_add_x_forwarded_for;
}
回答如下:

更多推荐

如何配置 AWS Elastic Beanstalk Nodejs Nginx Web 服务器以服务于 nodejs 应用程序以及使用 Angular 构建的静

本文发布于:2024-05-30 12:49:17,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1770514.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:应用程序   服务于   静态   服务器   Beanstalk

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!