[[["易于理解","easyToUnderstand","thumb-up"],["解决了我的问题","solvedMyProblem","thumb-up"],["其他","otherUp","thumb-up"]],[["很难理解","hardToUnderstand","thumb-down"],["信息或示例代码不正确","incorrectInformationOrSampleCode","thumb-down"],["没有我需要的信息/示例","missingTheInformationSamplesINeed","thumb-down"],["翻译问题","translationIssue","thumb-down"],["其他","otherDown","thumb-down"]],["最后更新时间 (UTC):2025-08-11。"],[],[],null,["# Access HTTP servers running on a workstation\n\nBy default you can access HTTP ports `80` and ports `1024` to `65535` on your\nworkstations from your browser. You can restrict the ports you can access on\nyour workstations by [setting `allowedPorts`](#restricting_port_access_for_a_workstation)\nin the workstation configuration.\n\nRunning workstations have a `host` property that you can use\nto connect using HTTP from a remote browser. You can find the `host` property by\ngetting details for a running workstation through the API, Google Cloud CLI,\nthe Google Cloud console, or by printing the `$WEB_HOST` environment variable,\nwhich is automatically set inside your workstation.\nThe URL connects on port `80` by default.\n\nDefault workstation URL format\n------------------------------\n\nThe `host` property URL uses the following format by default: \n\n https://\u003cvar translate=\"no\"\u003ePORT\u003c/var\u003e-\u003cvar translate=\"no\"\u003eWORKSTATION_NAME\u003c/var\u003e.\u003cvar translate=\"no\"\u003eCLUSTER_ID\u003c/var\u003e.cloudworkstations.dev\n\nThe placeholders represent the following:\n\n- \u003cvar translate=\"no\"\u003ePORT\u003c/var\u003e: the port number, which is port `80` by default.\n- \u003cvar translate=\"no\"\u003eWORKSTATION_NAME\u003c/var\u003e: the workstation name.\n- \u003cvar translate=\"no\"\u003eCLUSTER_ID\u003c/var\u003e: the randomly generated cluster identifier\n- `cloudworkstations.dev`: the default domain name for a workstation.\n\n URLs for custom domains use a different format. For more about setting up\n custom domains in Cloud Workstations, see\n [Set up custom domains for Cloud Workstations](/workstations/docs/set-up-custom-domains-for-cloud-workstations).\n\nConnect to a different port by changing the URL\n-----------------------------------------------\n\nIn order to connect on a different port, specify a different port number as a\nprefix. For example, the following URL connects to port `9900`: \n\n https://9900-myworkstation.cluster-12345abcde.cloudworkstations.dev\n\nIn this example, note the following:\n\n- `9900`: represents the port number.\n- `myworkstation`: represents the workstation ID.\n- `cluster-12345abcde`: represents the cluster identifier.\n- `cloudworkstations.dev`: represents the default domain name for a workstation.\n\nThese URLs require user authentication. To access these URLs,\nyou must be logged in and must have the Cloud Workstations User IAM\nrole, `roles/workstations.user`, or the `workstations.workstations.use`\npermission.\n\nConnecting to an HTTP app from Google Cloud console\n---------------------------------------------------\n\nYou can connect to an HTTP app running on a workstation from the\nGoogle Cloud console.\n\nFor any running workstation that you have permissions to use, you see a\n**Launch** button. By default, this button connects on port `80`. You can\nclick the arrow_drop_downexpander\narrow next to **Launch** to see alternative connecting options. The\n**Connect to web app on port** option lets you specify a different port to\nconnect to.\n\nConnecting to an HTTP app from the base editor\n----------------------------------------------\n\nTo connect to an app running on your workstation from the base editor, follow either of these instructions:\n\n- Click localhost links in the terminal. The base editor automatically\n redirects localhost links to the right URLs.\n\n 1. To open a terminal window, click menu\n **Menu** \\\u003e **Terminal** \\\u003e **New Terminal** .\n Alternatively, press \u003ckbd\u003eControl+Shift+`\u003c/kbd\u003e (or\n \u003ckbd\u003eCommand+Shift+`\u003c/kbd\u003e on macOS).\n\n 2. At the command prompt, run the following command to display the\n localhost link:\n\n echo http://localhost:\u003cvar translate=\"no\"\u003ePORT\u003c/var\u003e\n\n Replace \u003cvar translate=\"no\"\u003ePORT\u003c/var\u003e with a port number such as `80`\n or `8080`.\n 3. Hold \u003ckbd\u003eControl\u003c/kbd\u003e (or \u003ckbd\u003eCommand\u003c/kbd\u003e on macOS) and then click\n the localhost link. \n This opens\n \u003cvar translate=\"no\"\u003ePORT\u003c/var\u003e`-`\u003cvar translate=\"no\"\u003eWORKSTATION-HOSTNAME\u003c/var\u003e\n in your browser.\n\n- Use the browser window: navigate to\n `https://`\u003cvar translate=\"no\"\u003ePORT\u003c/var\u003e`-`\u003cvar translate=\"no\"\u003eWORKSTATION-HOSTNAME\u003c/var\u003e,\n where \u003cvar translate=\"no\"\u003ePORT\u003c/var\u003e is the port number and\n \u003cvar translate=\"no\"\u003eWORKSTATION-HOSTNAME\u003c/var\u003e is your workstation\n hostname.\n\nRestricting port access for a workstation\n-----------------------------------------\n\nTo restrict the ports that can be accessed on a workstations, set the\n`allowedPorts` in the workstation configurations.\n\nTo restrict a single port, set the [`PortRange`](./reference/rest/v1beta/projects.locations.workstationClusters.workstationConfigs#PortRange)\n`first` and `last` fields to the same port number.\n\nBy default ports `22`, `80` and `1024`-`65535` are allowed.\n\nTo create a workstation configuration with restricted port access to `80` and\n`8080` to `8100`, run the following Google Cloud CLI command: \n\n```\n gcloud beta workstations configs create CONFIG \\\n --cluster=CLUSTER_ID \\\n --region=REGION \\\n --project=PROJECT \\\n --allowed-ports=first=80,last=80 \\\n --allowed-ports=first=8080,last=8100\n```\n\nCORS preflight requests\n-----------------------\n\nBy default, the workstations service makes sure that all requests to the\nworkstation are [authenticated](/workstations/docs/authentication#http) with a\ncookie or authentication header.\n\nCross-Origin Resource Sharing (CORS) preflight requests don't include cookies\nor custom headers, and so are considered unauthenticated and blocked by the\nworkstations service. Administrators can\noptionally allow unauthenticated CORS preflight requests through to\nthe workstation, where it becomes the responsibility of the destination\nserver in the workstation to validate the request.\n\nTo allow unauthenticated CORS preflight requests, run the following\nGoogle Cloud CLI command: \n\n```\n gcloud beta workstations configs update CONFIG \\\n --cluster=CLUSTER_ID \\\n --region=REGION \\\n --project=PROJECT \\\n --allow-unauthenticated-cors-preflight-requests\n```\n\nDisable localhost replacement in HTTP responses\n-----------------------------------------------\n\nTo allow applications under development to run properly on the\nworkstation, Cloud Workstations replaces references to localhost,\n127.0.0.1, and to 0.0.0.0 with the workstation's hostname in HTTP\nresponses from the workstation.\n\nThis may intefere with some applications. To disable this behavior,\nrun the following Google Cloud CLI command: \n\n```\n gcloud beta workstations configs update CONFIG \\\n --cluster=CLUSTER_ID \\\n --region=REGION \\\n --project=PROJECT \\\n --disable-localhost-replacement\n```"]]