Symfony中的web应用程序无法通过本地主机上的app_DOMAIN访问



我在本地机器上部署了一个Symfony应用程序。以下是相关的.env文件

###> symfony/framework-bundle ###
APP_ENV=dev
APP_SECRET=******
APP_DOMAIN=myapp.test
API_DOMAIN=api.myapp.test
###> symfony/swiftmailer-bundle ###
# For Gmail as a transport, use: "gmail://username:password@localhost"
# For a generic SMTP server, use: "smtp://localhost:25?encryption=&auth_mode="
# Delivery is disabled by default via "null://localhost"
MAILER_URL=smtp://localhost:1025
###< symfony/swiftmailer-bundle ###
###> doctrine/doctrine-bundle ###
# Format described at http://docs.doctrine-project.org/projects/doctrine-dbal/en/latest/reference/configuration.html#connecting-using-a-url
# For an SQLite database, use: "sqlite:///%kernel.project_dir%/var/data.db"
# Configure your db driver and server_version in config/packages/doctrine.yaml
DATABASE_URL=postgres://postgres@127.0.0.1:5432/myapp_dev
TEST_DATABASE_URL=postgres://postgres@127.0.0.1:5432/myapp_test
###< doctrine/doctrine-bundle ###
###> sentry/sentry-symfony ###
SENTRY_DSN=
###< sentry/sentry-symfony ###
......

我用调用程序运行服务器

port=8000
command=bin/console server:run

仓/控制台为

#!/usr/bin/env php
<?php
use AppKernel;
use SymfonyBundleFrameworkBundleConsoleApplication;
use SymfonyComponentConsoleInputArgvInput;
use SymfonyComponentDebugDebug;
use SymfonyComponentDotenvDotenv;
set_time_limit(0);
require __DIR__.'/../vendor/autoload.php';
if (!class_exists(Application::class)) {
throw new RuntimeException('You need to add "symfony/framework-bundle" as a Composer dependency.');
}
if (!isset($_SERVER['APP_ENV'])) {
if (!class_exists(Dotenv::class)) {
throw new RuntimeException('APP_ENV environment variable is not defined. You need to define environment variables for configuration or add "symfony/dotenv" as a Composer dependency to load variables from a .env file.');
}
(new Dotenv())->load(__DIR__.'/../.env');
}
$input = new ArgvInput();
$env = $input->getParameterOption(['--env', '-e'], $_SERVER['APP_ENV'] ?? 'dev', true);
$debug = (bool) ($_SERVER['APP_DEBUG'] ?? ('prod' !== $env)) && !$input->hasParameterOption('--no-debug', true);
if ($debug) {
umask(0000);
if (class_exists(Debug::class)) {
Debug::enable();
}
}
$kernel = new Kernel($env, $debug);
$application = new Application($kernel);
$application->run($input);

问题是:我可以通过127.0.0.1:8000访问web应用程序,但不能通过myapp.test访问。我需要通过myapp.test访问。为什么它不起作用

您需要修改您的HOSTS文件以将myapp.test注册为127.0.0.1:8000,或者您可以使用Symfony的本地代理

相关内容

  • 没有找到相关文章