Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/google-cloud-platform/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Google cloud platform 云运行是否需要NGINX?_Google Cloud Platform_Google Cloud Run - Fatal编程技术网

Google cloud platform 云运行是否需要NGINX?

Google cloud platform 云运行是否需要NGINX?,google-cloud-platform,google-cloud-run,Google Cloud Platform,Google Cloud Run,我正在为我的博客和工作网站使用cloud run,我真的很喜欢它。 我已经根据谷歌教程通过容器化部署了python API和Vue/Nuxt应用程序。 有一件事我不明白,为什么不需要在前端安装NGINX # Use the official lightweight Node.js 12 image. # https://hub.docker.com/_/node FROM node:12-slim # Create and change to the app directory. WORKDI

我正在为我的博客和工作网站使用cloud run,我真的很喜欢它。 我已经根据谷歌教程通过容器化部署了python API和Vue/Nuxt应用程序。 有一件事我不明白,为什么不需要在前端安装NGINX

# Use the official lightweight Node.js 12 image.
# https://hub.docker.com/_/node
FROM node:12-slim

# Create and change to the app directory.
WORKDIR /usr/src/app

# Copy application dependency manifests to the container image.
# A wildcard is used to ensure both package.json AND package-lock.json are copied.
# Copying this separately prevents re-running npm install on every code change.
COPY package*.json ./

# Install production dependencies.
RUN npm install --only=production

# Copy local code to the container image.
COPY . ./

# Run the web service on container startup.
RUN npm run build
CMD [ "npm", "start" ]
所有这些都可以在我不打电话给Nginx的情况下运行。
但是我读了很多文章,人们将NGINX打包到他们的容器中。所以我想澄清一下。我所做的有什么缺点吗?

使用NGINX或静态文件服务器的一个显著优点是容器映像的大小。当服务SPA(没有SSR)时,您所需要的只是将捆绑的文件发送到客户端。不需要捆绑编译应用程序所需的构建依赖项或运行时

您的第一个映像是将带有依赖项的整个源代码复制到映像中,而您所需要的(如果没有运行SSR)只是编译后的文件。NGINX可以为您提供“静态站点服务器”,它只为您的构建服务,是一个轻量级的解决方案


关于python,除非您能以某种方式捆绑它,否则在没有NGINX的情况下使用它看起来还不错。

Ahhh非常感谢您!我在努力寻找一个好的答案。所以基本上对于nodejs来说,如果它是SPA,我可以只包含nginx来服务静态文件。但是,如果是SSR,我就不需要了?此外,firebase托管比用于SPA应用的NGINX容器有优势,对吗?关于firebase,我建议您使用它,对于SPA来说,它比在云上运行要简单得多。现在,SSR可能需要运行时和编译包,但这是特定于框架的。查看Vue文档,了解如何为SSR提供最小捆绑包:)简而言之,Cloud Run需要运行web服务器的容器映像。您可以编写自己的服务器(在Go、Java、Python、Node.js中)来服务您的博客,或者在应用程序前面运行nginx、Apache、HAProxy、envilege或其他任何东西——这部分由您决定。也就是说,并不是所有语言都提供现成的HTTP服务器(例如PHP)。@AhmetB Google我理解,但我很好奇,Cloud Run是否在前端有一个代理,这就是为什么我只运行gunicorn就足够了,因为Cloud Run前端有类似Nginx的东西?我不确定你为什么想知道这个问题的答案。Gunicorn是Python应用程序的“生产就绪”代理。你问题的答案实际上对你没有帮助。但是,是的,Cloud Run在你的应用程序前面有一个代理,用于容器之间的负载平衡和执行身份验证等。
# Use the official lightweight Python image.
# https://hub.docker.com/_/python
FROM python:3.7-slim

# Copy local code to the container image.
ENV APP_HOME /app
WORKDIR $APP_HOME
COPY . ./

# Install production dependencies.
RUN apt-get update && apt-get install -y \
libpq-dev \
gcc
RUN pip install -r requirements.txt

# Run the web service on container startup. Here we use the gunicorn
# webserver, with one worker process and 8 threads.
# For environments with multiple CPU cores, increase the number of workers
# to be equal to the cores available.
CMD exec gunicorn -b :$PORT --workers=4 main:server