简体   繁体   English

如何使用 apache2 将 Laravel API 配置为端口 8000?

[英]How to configure Laravel API to port 8000 with apache2?

I am new to apache2 and DigitalOccean.我是 apache2 和 DigitalOccean 的新手。 I have a Laravel project API.我有一个 Laravel 项目 API。 I installed php mysql and apache2 on DigitalOcean server.我在 DigitalOcean 服务器上安装了 php mysql 和 apache2。 I want to access the API with IP address and Port number 8000 (Like http://139.59.28.165:8000 ) (Port 8000 enabled in firewall).我想使用 IP 地址和端口号 8000(如http://139.59.28.165:8000 )(在防火墙中启用端口 8000)访问 API。 But when I browse the link http://139.59.28.165:8000 , it shows This site can't be reached .但是当我浏览链接http://139.59.28.165:8000 时,它显示This site can't be reached

此网站无法打开

But without port number it shows the directory但没有端口号,它显示目录

在此处输入图片说明

But I want with IP address and Port number like this:但我想要这样的 IP 地址和端口号: 在此处输入图片说明

Current DocumentRoot(/etc/apache2/sites-available/000-default.conf)当前 DocumentRoot(/etc/apache2/sites-available/000-default.conf)

<VirtualHost *:80>

    ServerAdmin webmaster@localhost
    DocumentRoot /var/www/crm-api


    ErrorLog ${APACHE_LOG_DIR}/error.log
    CustomLog ${APACHE_LOG_DIR}/access.log combined

</VirtualHost>

# vim: syntax=apache ts=4 sw=4 sts=4 sr noet

Change the port in your vhost to 8000将 vhost 中的端口更改为 8000

<VirtualHost *:8000>

    ServerAdmin webmaster@localhost
    DocumentRoot /var/www/crm-api


    ErrorLog ${APACHE_LOG_DIR}/error.log
    CustomLog ${APACHE_LOG_DIR}/access.log combined

</VirtualHost>

# vim: syntax=apache ts=4 sw=4 sts=4 sr noet

Also you may want to set the DocumentRoot to /var/www/crm-api/public您还可能希望将 DocumentRoot 设置为/var/www/crm-api/public

Laravel specifies that the public folder should be the document root. Laravel 指定公共文件夹应该是文档根目录。

Then go ahead and restart apache.然后继续并重新启动apache。

You have to change the port of your virtualhost to 8000 And add public at the end of DocumentRoot.您必须将虚拟主机的端口更改为 8000 并在 DocumentRoot 的末尾添加 public 。 desable an enable your config.禁用并启用您的配置。

<VirtualHost *:8000>

   ServerAdmin webmaster@localhost
   DocumentRoot /var/www/crm-api/public


  ErrorLog ${APACHE_LOG_DIR}/error.log
  CustomLog ${APACHE_LOG_DIR}/access.log combined

</VirtualHost>

It's like apache2 don't listen to 8000 you have to anable it by editing /etc/apache2/port.conf and restart the server就像 apache2 不听 8000 你必须通过编辑 /etc/apache2/port.conf 并重新启动服务器来启用它

Listen 80
Listen 8000
<IfModule ssl_module>
    Listen 443
</IfModule>

 <IfModule mod_gnutls.c>
    Listen 443
 </IfModule>

vim: syntax=apache ts=4 sw=4 sts=4 sr noet vim: 语法=apache ts=4 sw=4 sts=4 sr noet

Try this尝试这个

Create a configuration file on the server name by sudo nano /etc/apache2/sites-available/139.59.28.165:8000.conf and add the following contents通过sudo nano /etc/apache2/sites-available/139.59.28.165:8000.conf在服务器名称上创建配置文件并添加以下内容

<VirtualHost *:8000>
        ServerName 139.59.28.165:8000
        ServerAdmin webmaster@localhost
        DocumentRoot /var/www/crm-api/public

        ErrorLog ${APACHE_LOG_DIR}/error.log
        CustomLog ${APACHE_LOG_DIR}/access.log combined

        <Directory /var/www/crm-api>
                AllowOverride All
        </Directory>

</VirtualHost>

Run the following command运行以下命令

sudo a2dissite 000-default.conf
sudo a2ensite 139.59.28.165:8000.conf
sudo a2enmod rewrite
sudo service apache2 restart

Add the following in the hosts file /etc/hostshosts文件/etc/hosts添加以下内容

127.0.0.1 139.59.28.165

And also add your port in ports configuration /etc/apache2/ports.conf并在ports configuration /etc/apache2/ports.conf添加您的端口

Listen 8000

Don't forget to restart the apache2 sudo service apache2 restart不要忘记重启apache2 sudo service apache2 restart

如果您使用 wamp 或 xampp,则需要从本地服务器更改端口,您应该从 Apache 配置文件更改它并将其设为 8000 而不是 80

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM