Organiza tus páginas con colecciones
Guarda y categoriza el contenido según tus preferencias.
En este instructivo, se muestra cómo usar Compute Engine para implementar Apache Web Server en una instancia de máquina virtual (VM). Si deseas obtener más información sobre las tecnologías que puedes usar para la entrega web enGoogle Cloud, consulta Elige una opción de hosting enGoogle Cloud.
Una VM en Compute Engine se puede controlar como cualquier servidor estándar de Linux. Implementa Apache Web Server para conocer los conceptos básicos de la ejecución de un servidor en una instancia de VM.
Requisitos previos
Para crear una VM de Linux que permita el tráfico HTTP, haz lo siguiente:
Opcional: Mientras creas una VM de Linux, puedes seleccionar la casilla de verificación Permitir tráfico HTTP a fin de abrir el puerto tcp:80 para el tráfico y la casilla de verificación Permitir tráfico HTTPS a fin de abrir el puerto tcp:443. Sin embargo, si
deseas abrir un puerto diferente, configura el firewall
después de crear la VM y, luego, configura Apache
para usar el firewall.
Para conectarte a la VM de Linux que acabas de crear, haz clic en SSH en la fila de la VM.
Para actualizar los paquetes disponibles y, luego, instalar el paquete apache2, usa el administrador de paquetes del sistema de ese sistema operativo.
Si seguiste la guía de inicio rápido, se creará una VM de Ubuntu. Para actualizar una VM de Ubuntu, ejecuta el siguiente comando:
sudo apt update && sudo apt -y install apache2
Después de instalar Apache, el sistema operativo inicia el servidor Apache de forma automática.
Verifica que Apache esté en ejecución:
sudo systemctl status apache2
Reemplaza la página web predeterminada de Apache Web Server:
Haz clic en la IP externa de tu instancia en la columna de IP externa.
En el navegador, ve a http://[EXTERNAL_IP]. No te conectes mediante https porque esto hace que el servidor muestre un error Connection Refused.
Debería ver la página "Hello World!".
Limpia
Para evitar que se apliquen cargos por la VM una vez que termines de experimentar, bórrala. Para obtener más información, consulta Cómo realizar una limpieza.
Soluciona problemas
Cuando recibes un error Connection Refused
Si te aparece un error Connection Refused, es posible que se den estas situaciones:
Tu instancia de VM no es accesible a nivel público porque la configuración de tus etiquetas o reglas de firewall tiene alguno de los errores siguientes:
La instancia de VM no tiene la etiqueta correspondiente que permite que Compute Engine aplique las reglas de firewall adecuadas a tu instancia.
Tu proyecto no tiene una regla de firewall que permita dirigir el tráfico a la dirección IP externa de tu instancia.
Intentas acceder a la VM mediante una dirección https. Verifica que la URL sea http://[EXTERNAL_IP] y no https://[EXTERNAL_IP].
Para asegurarte de que la instancia de VM tenga las etiquetas correctas, sigue estos pasos:
En la Google Cloud consola, ve a la página Instancias de VM.
Si es la primera vez que usas Google Cloud, crea una cuenta para evaluar el rendimiento de Compute Engine en situaciones reales. Los clientes nuevos también obtienen $300 en créditos gratuitos para ejecutar, probar y, además, implementar cargas de trabajo.
[[["Fácil de comprender","easyToUnderstand","thumb-up"],["Resolvió mi problema","solvedMyProblem","thumb-up"],["Otro","otherUp","thumb-up"]],[["Difícil de entender","hardToUnderstand","thumb-down"],["Información o código de muestra incorrectos","incorrectInformationOrSampleCode","thumb-down"],["Faltan la información o los ejemplos que necesito","missingTheInformationSamplesINeed","thumb-down"],["Problema de traducción","translationIssue","thumb-down"],["Otro","otherDown","thumb-down"]],["Última actualización: 2025-09-03 (UTC)"],[[["\u003cp\u003eThis tutorial guides you through deploying an Apache web server on a Compute Engine virtual machine (VM) instance, providing a foundation for running a server on a VM.\u003c/p\u003e\n"],["\u003cp\u003eThe process involves creating a Linux VM, connecting to it via SSH, and installing the \u003ccode\u003eapache2\u003c/code\u003e package using the system package manager, which will automatically start the server.\u003c/p\u003e\n"],["\u003cp\u003eYou can verify Apache is running, overwrite the default web page with custom content, and then test the server by accessing its external IP address in a web browser using \u003ccode\u003ehttp://[EXTERNAL_IP]\u003c/code\u003e.\u003c/p\u003e\n"],["\u003cp\u003eTroubleshooting steps are provided for resolving "Connection Refused" errors, which often involve checking firewall rules and ensuring that the VM allows HTTP traffic on port 80, along with confirming the correct URL format is used.\u003c/p\u003e\n"],["\u003cp\u003eAfter completion, the guide suggests exploring further options such as hosting a full website or setting up LAMP stack on Compute Engine.\u003c/p\u003e\n"]]],[],null,["# Running a basic Apache web server\n\nThis tutorial shows you how to use Compute Engine to deploy an Apache web\nserver on a virtual machine (VM) instance. To learn more about the technologies\nthat you can use for web serving on\nGoogle Cloud, see [Choosing a hosting option on\nGoogle Cloud](/architecture/web-serving-overview#choosing_an_option).\n\nA VM on Compute Engine can be controlled like\nany standard Linux server. Deploy an Apache web server to learn the\nbasics of running a server on a VM instance.\n\nPrerequisites\n-------------\n\nCreate a Linux VM that allows HTTP traffic by doing the following:\n\n1. Create a new Linux VM. For more information, see [Quickstart using a Linux\n VM](/compute/docs/create-linux-vm-instance).\n\n 1. Optional: While creating a Linux VM, you can select the **Allow HTTP\n traffic** checkbox to open port `tcp:80` for traffic and **Allow HTTPS\n traffic** checkbox to open port `tcp:443`. However, if you want to open a different port, [configure the firewall](/vpc/docs/using-firewalls) after creating the VM, and then [configure Apache](https://httpd.apache.org/docs/2.4/bind.html) to use the firewall.\n2. Connect to the Linux VM. For more information, see [Connect to the\n VM instance](/compute/docs/create-linux-vm-instance#connect_to_the_vm_instance).\n\nInstall Apache\n--------------\n\n1. In the Google Cloud console, go to the **VM Instances** page.\n\n [Go to VM instances](https://console.cloud.google.com/compute/instances)\n2. To connect to the Linux VM you just created, click **SSH** in the row of the VM.\n3. To update the available packages and\n install the `apache2` package, use the system package manager for that operating system.\n If you followed the Quickstart, this creates an Ubuntu VM. To update an\n Ubuntu VM, run the following command:\n\n sudo apt update && sudo apt -y install apache2\n\n After installing Apache, the operating system automatically starts the\n Apache server.\n4. Verify that Apache is running:\n\n sudo systemctl status apache2\n\n5. Overwrite the Apache web server default web page:\n\n echo '\u003c!doctype html\u003e\u003chtml\u003e\u003cbody\u003e\u003ch1\u003eHello World!\u003c/h1\u003e\u003c/body\u003e\u003c/html\u003e' | sudo tee /var/www/html/index.html\n\nTest your server\n----------------\n\nTest that your VM is serving traffic on its external IP.\n\n1. In the Google Cloud console, go to the **VM Instances** page.\n\n [Go to VM instances](https://console.cloud.google.com/compute/instances)\n2. Copy the external IP for your VM under the **External IP** column.\n3. In a browser, navigate to `http://[EXTERNAL_IP]`. Don't connect using `https` because this causes the server to return a `Connection Refused` error.\n\nYou should now see the \"Hello World!\" page.\n\nClean up\n--------\n\nTo avoid incurring charges for the VM after you're done experimenting, delete\nthe VM. For more information, see [Clean up](/compute/docs/create-linux-vm-instance#clean-up).\n\nTroubleshooting\n---------------\n\n**Receiving a `Connection Refused` error**\n\nIf you are seeing a `Connection Refused` error, it is possible that:\n\n- Your VM instance is not publicly accessible because your firewall rules or\n tags are misconfigured in one of the following ways:\n\n - The VM instance does not have the proper tag that allows Compute Engine to apply the appropriate firewall rules to your instance.\n - Your project does not have a firewall rule that allows traffic to the external IP address for your instance.\n- You are trying to access the VM using an `https` address. Check that your\n URL is `http://[EXTERNAL_IP]` rather than `https://[EXTERNAL_IP]`.\n\nTo ensure that your VM instance has the correct tags:\n\n1. In the Google Cloud console, go to the **VM instances** page.\n\n [Go to VM instances](https://console.cloud.google.com/compute/instances)\n2. Click the name of the instance that you are trying to connect to.\n3. Click **Edit** at the top of the page.\n4. Scroll down to **Firewalls** , and make sure the **Allow HTTP traffic** box is checked. If it is not checked, check it.\n5. Save your changes. This ensures that the correct tags are added to the VM instance.\n\nTo ensure that the correct firewall rule exists:\n\n1. In the Google Cloud console, go to the **Firewall rules** page.\n\n [Go to Firewall rules](https://console.cloud.google.com/networking/firewalls)\n2. Look for a firewall rule that allows all IP ranges through tcp:80. Usually, this rule is named the `default-allow-http` rule.\n3. If a rule does not exist, create one.\n 1. Click **Create firewall rule**.\n 2. Enter a name for the rule, such as `default-allow-http`.\n 3. Under **Source IP ranges** , enter `0.0.0.0/0` to allow traffic from all sources.\n 4. Under **Protocols and ports** , check **Specified protocols and ports** and enter `tcp:80`.\n 5. Create your firewall rule.\n\nTest your server again by going to the external IP address of the instance: \n\n http://[EXTERNAL_IP]\n\nWhat's next\n-----------\n\nLearn how to [host a website on Compute Engine](/solutions/web-serving-overview).\n\nLearn how to [set up LAMP on Compute Engine](https://github.com/GoogleCloudPlatform/community/blob/master/archived/setting-up-lamp/index.md).\n\nTry it for yourself\n-------------------\n\n\nIf you're new to Google Cloud, create an account to evaluate how\nCompute Engine performs in real-world\nscenarios. New customers also get $300 in free credits to run, test, and\ndeploy workloads.\n[Try Compute Engine free](https://console.cloud.google.com/freetrial)"]]