Laravel Aws Nginx 一个弹性 IP 上的多个项目

发布于 2025-01-15 04:02:09 字数 1433 浏览 0 评论 0原文

我对 AWS Laravel 部署相当陌生,我之前一直在使用 Hostgator,并且在那里管理多个域相当容易。然而,我想做的事情非常有限,所以我们决定看看 AWS。

我所拥有的:

  • ec2 实例
  • 与实例关联的
  • 弹性 IP安装的 Ubuntu 18.04
  • 安装的 Nginx
  • Laravel 8 项目

现在正在测试多个项目的部署。我创建了多个 EC2 实例(免费实例)。我成功了。 现在的问题是我想利用成本核算。 **是否可以为尚无域的多个项目仅运行一个实例。

例如:

  • 暂存项目 1 可访问 @ 18.186.128.145:5000
  • 暂存项目 2 可访问 @ 18.186.128.145:9000

我一直在本地环境中执行此操作。我只是不知道 AWS Nginx 部署是否完全可能

这是我的工作 Nginx 配置文件。 (顺便说一句,示例中的随机 IP )

server {
    listen 80;
    server_name 18.186.128.145;
    root /var/www/laravel/project-staging-1/public;

    add_header X-Frame-Options "SAMEORIGIN";
    add_header X-XSS-Protection "1; mode=block";
    add_header X-Content-Type-Options "nosniff";

    index index.html index.htm index.php;

    charset utf-8;

    location / {
        try_files $uri $uri/ /index.php?$query_string;
    }

    error_page 404 /index.php;

    location ~ \.php$ {
        fastcgi_pass unix:/var/run/php/php7.4-fpm.sock;
        fastcgi_index index.php;
        fastcgi_param SCRIPT_FILENAME $realpath_root$fastcgi_script_name;
        include fastcgi_params;
    }

    location ~ /\.(?!well-known).* {
        deny all;
    }
}

我已经到处搜索,但我所能看到的只是带有托管域名的示例,或者带有子文件夹或子域的示例。如果有现有的答案,请指出给我,我将不胜感激。

我还不知道我所想的是否真的可能。如果可以的话,请给我建议,如果这是不可能的话,可以采取更好的行动。太感谢了

I'm fairly new to AWS Laravel Deployment, I had been using Hostgator before and management of multiple domains is fairly easy there. however I'm quite limited with things I want to do so we decided to check out AWS.

What I have:

  • ec2 instance
  • elastic ip associated to the instance
  • Installed Ubuntu 18.04
  • Installed Nginx
  • Laravel 8 Project

for now Im testing deployment of multiple projects. I created Multiple EC2 instances ( the free one). and I got it working. the question now is I want to leverage costing. **Is it possible to have only one instance running for multiple projects that doesnt have a domain yet.

like for ex:

  • staging project 1 is accessible @
    18.186.128.145:5000
  • staging project 2 is accessible @
    18.186.128.145:9000

I had been doing this on my local environment. I just dont know if its quite possible with AWS Nginx deployment

Here's my working Nginx Config File. ( Random IP in the example btw )

server {
    listen 80;
    server_name 18.186.128.145;
    root /var/www/laravel/project-staging-1/public;

    add_header X-Frame-Options "SAMEORIGIN";
    add_header X-XSS-Protection "1; mode=block";
    add_header X-Content-Type-Options "nosniff";

    index index.html index.htm index.php;

    charset utf-8;

    location / {
        try_files $uri $uri/ /index.php?$query_string;
    }

    error_page 404 /index.php;

    location ~ \.php$ {
        fastcgi_pass unix:/var/run/php/php7.4-fpm.sock;
        fastcgi_index index.php;
        fastcgi_param SCRIPT_FILENAME $realpath_root$fastcgi_script_name;
        include fastcgi_params;
    }

    location ~ /\.(?!well-known).* {
        deny all;
    }
}

I have searched everywhere but all I could see are examples with a hosted domain name, or ones with sub folders or sub domains. If there is an existing answer please point it out to me I'll appreciate it.

I don't know yet if what im onto is actually possible. If you can, please give me advice on better move to do if this is not possible. Thank you so much

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

煞人兵器 2025-01-22 04:02:09

我使之成为可能。

我已经将 nginx 在“ufw”中监听的端口列入白名单但是
事实证明,我的 AWS Ec2 实例中也有“安全组”,我还需要将要使用的端口列入白名单。

  • 因此,将安全组的入站规则中的端口列入白名单,
  • 允许ufw中的端口
  • 编辑nginx配置文件以侦听您要使用的端口,
  • 如果您打算开放多个端口,则可以创建多个服务器块。

I was able to make it possible.

I already whitelisted the ports nginx is listening to in "ufw" however
it turns out, I also have "security groups" in my AWS Ec2 Instance where I also need to whitelist the ports i'm gonna be using.

  • So Whitelist the ports in the inbound rules of the security group
  • allow the ports in ufw
  • edit the nginx config file to listen to the ports you want to use
  • you may create multiple server blocks if you're planning to open up multiple ports.
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文