【问题标题】:Change from Localhost to server IP doesn't work从 localhost 更改为服务器 IP 不起作用
【发布时间】:2022-01-05 23:21:59
【问题描述】:

我目前正在将一个 laravel 应用程序部署到一个 ubuntu 虚拟机上,经过一番头疼后它终于工作了,我可以在运行 php artisan serve 后在 127.0.0.1:8000 看到该网站! :)

但是,我尝试将地址从 localhost 更改为服务器的 IP。

我的 ´/etc/hosts` 文件如下所示:

127.0.0.1 localhost
132.231.36.101 laravel.dev
127.0.1.1 lehner-grund01

我还尝试将 127... 地址作为一个整体删除,但没有任何改变。

在我的.env 文件中,我有这个:

APP_NAME=Laravel
APP_ENV=local
APP_KEY=<my_key>
APP_DEBUG=true
APP_URL=http://132.231.36.101

我也尝试更改 ServeCommand.php 文件中的 IP - 也没有用。

/etc/apache2/sites-available/ 中的我的 conf 文件如下所示:

名称虚拟主机 *:8080 听8080

<VirtualHost *:8080>
    ServerAdmin admin@example.com
    ServerName laravel.dev
    ServerAlias www.laravel.dev
    DocumentRoot grup1/project/tose-gruppe-1/public

    <Directory /home/user/projects/laravel_project/public/>
            Options Indexes FollowSymLinks MultiViews
            AllowOverride All
            Order allow,deny
            allow from all
            Require all granted
    </Directory>

    LogLevel debug
    ErrorLog ${APACHE_LOG_DIR}/error.log
    CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>

我在运行php artisan serve 时尝试“手动”添加主机,如下所示:

php artisan serve --host=&lt;my_ip&gt; --port

这是我第一次在 ubuntu 机器上部署一些东西,我已经完成了哈哈。现在尝试了七个小时,任何帮助表示赞赏!

编辑: 使用状态命令时的消息:

● apache2.service - The Apache HTTP Server
     Loaded: loaded (/lib/systemd/system/apache2.service; enabled; vendor preset: enabled)
     Active: active (running) since Wed 2022-01-05 21:43:04 UTC; 1h 59min ago
       Docs: https://httpd.apache.org/docs/2.4/
    Process: 47274 ExecStart=/usr/sbin/apachectl start (code=exited, status=0/SUCCESS)
    Process: 48577 ExecReload=/usr/sbin/apachectl graceful (code=exited, status=0/SUCCESS)
   Main PID: 47278 (apache2)
      Tasks: 8 (limit: 4575)
     Memory: 17.2M
     CGroup: /system.slice/apache2.service
             ├─47278 /usr/sbin/apache2 -k start
             ├─48581 /usr/sbin/apache2 -k start
             ├─48582 /usr/sbin/apache2 -k start
             ├─48583 /usr/sbin/apache2 -k start
             ├─48584 /usr/sbin/apache2 -k start
             ├─48585 /usr/sbin/apache2 -k start
             ├─48820 /usr/sbin/apache2 -k start
             └─48826 /usr/sbin/apache2 -k start

Jan 05 21:43:04 lehner-tse01 systemd[1]: Starting The Apache HTTP Server...
Jan 05 21:43:04 lehner-tse01 apachectl[47277]: AH00112: Warning: DocumentRoot [/var/www/html/tose-gruppe-1/public] does not exist
Jan 05 21:43:04 lehner-tse01 systemd[1]: Started The Apache HTTP Server.
Jan 05 22:03:58 lehner-tse01 systemd[1]: Reloading The Apache HTTP Server.
Jan 05 22:03:58 lehner-tse01 apachectl[48580]: AH00112: Warning: DocumentRoot [/var/www/html/tose-gruppe-1/public] does not exist
Jan 05 22:03:58 lehner-tse01 apachectl[48580]: AH00548: NameVirtualHost has no effect and will be removed in the next release /etc/apache2/sites-enabl>
Jan 05 22:03:58 lehner-tse01 apachectl[48580]: AH00112: Warning: DocumentRoot [/etc/apache2/grup1/project/tose-gruppe-1/public] does not exist
Jan 05 22:03:58 lehner-tse01 systemd[1]: Reloaded The Apache HTTP Server.

我不明白为什么文档根目录是错误的,应该是正确的

【问题讨论】:

    标签: php laravel apache ubuntu deployment


    【解决方案1】:

    APP_URL=http://132.231.36.101 不必更改为公共地址,因为当您将端口 80 转发到您的服务器时,它会自动重定向到您的服务器。意思是它去本地主机。不需要公开地址

    【讨论】:

    • APP_URL=http://localhost
    • 但是通过执行sudo service apache2 status来检查服务器是否完全启用
    • 是的,这意味着它在线,但是您是否编辑了 APP_URL ?
    • 编辑 /etc/hosts 到:127.0.0.1 laravel.dev(在 url 中输入 laravel.dev 时,您会转到 localhost)并输入 APP_URL=http://localhost 以及为什么您的虚拟主机有 2 条路由?
    • 您不应该通过 artisan serve 访问它,而是通过原始 localhost url 访问它,也在这里:DocumentRoot grup1/project/tose-gruppe-1/public&lt;Directory /home/user/projects/laravel_project/public/&gt;
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-02-10
    • 1970-01-01
    • 1970-01-01
    • 2017-06-26
    • 2018-12-27
    • 1970-01-01
    相关资源
    最近更新 更多