是否可以将 NGINX 用作反向代理并提供静态文件?

Is it posible to use NGINX as a reverse proxy and to serve static files?

提问人:Carlos Martínez 提问时间:11/10/2023 更新时间:11/10/2023 访问量:15

问:

目前我有两台服务器。一个带有 moodle,另一个带有 Angular 应用程序。

Moodle 上的 .conf 文件是:

server {
    listen 80;
    root /var/www/html/moodle;
    index  index.php index.html index.htm;
    server_name  moodle.example.com;

    client_max_body_size 100M;
    autoindex off;
    location / {
        try_files $uri $uri/ =404;
    }

    location /dataroot/ {
      internal;
      alias /var/www/html/moodledata/;
    }

    location ~ [^/].php(/|$) {
        include snippets/fastcgi-php.conf;
        fastcgi_pass unix:/run/php/php7.4-fpm.sock;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        include fastcgi_params;
    }
}

Angular 应用程序 .conf 是:

server {
        listen              443 ssl;
        listen          [::]:443 ssl;
        server_name         example.co;

        ssl_certificate     /etc/nginx/cer/cer.pem;
        ssl_certificate_key /etc/nginx/cer/cer.key;

        location /api/ {
        proxy_pass https://127.0.0.1:8051/;
        }
        location / {
        proxy_pass http://127.0.0.1:3000;
        }  
        location /inti {
        proxy_pass http://127.0.0.1:8080;
        }
}

是否可以同时使用 443 端口 (https) 提供两种解决方案?在单个服务器中?

我尝试了以下方法:

server {
        listen              443 ssl;
        listen          [::]:443 ssl;
        server_name         example.com;
        root /var/www/html;
        index  index.php index.html index.htm;

              ssl_certificate     /etc/nginx/cer/cer.pem;
              ssl_certificate_key /etc/nginx/cer/cer.key;
        client_max_body_size 100M;
    autoindex off;
    location /moodle/ {
        alias /var/www/html/moodle;
        try_files $uri $uri/ @backend;
    }

    location @backend {
        proxy_pass http://127.0.0.1:8080;
    }

    location /dataroot/ {
      internal;
      alias /var/www/html/moodledata/;
    }

    location ~ /moodle/[^/].php(/|$) {
        include snippets/fastcgi-php.conf;
        fastcgi_pass unix:/run/php/php7.4-fpm.sock;
        alias /var/www/html/moodle;
        fastcgi_param SCRIPT_FILENAME $request_filename;
        include fastcgi_params;
    }

              location /api/ {
              proxy_pass https://127.0.0.1:8051/;
               }
              location / {
              proxy_pass http://127.0.0.1:3000;
       }  location /inti {
        proxy_pass http://127.0.0.1:8080;
        }
}

但我目前无法访问 example.com/moodle。我还检查了文件夹文件的权限,甚至所有文件夹文件。/var/www/html/moodlechmod 777

Angular Nginx Moodle

评论


答: 暂无答案