【问题标题】:PHP API is not working With Django on apache2 Ubuntu server | Google CloudPHP API 无法在 apache2 Ubuntu 服务器上使用 Django |谷歌云
【发布时间】:2019-12-12 06:15:09
【问题描述】:

我已在 Google Cloud 上的 Linux Ubuntu 机器上的 apache2 Web 服务器上成功部署了一个 Django 项目。它工作正常。此外,我有与 MySQL 数据库连接的 PHP API,与 Django 连接的相同。但问题是 Django 应用程序工作正常,而 PHP API 无法正常工作。

我还将index.html 页面放在我的/var/www/html/api_folder/index.php 路径中。所以当我在浏览器中输入my_ip/api_folder 时,它会打开index.html 页面,但API 不起作用。 api 文件在api_folder 中,就像在index.html 页面中一样。

下面是我在 apache2 的 /sites-available 目录中的 conf 文件。即使是基本的 PHP 文件也可以工作并在 echo 中打印消息。 但是当我输入 My_ip/api_folder/api/get_about_us/?key=xxxx 时,它会显示 404 错误页面。

<VirtualHost *:80>
    # The ServerName directive sets the request scheme, hostname and port that
    # the server uses to identify itself. This is used when creating
    # redirection URLs. In the context of virtual hosts, the ServerName
    # specifies what hostname must appear in the request's Host: header to
    # match this virtual host. For the default virtual host (this file) this
    # value is not decisive as it is used as a last resort host regardless.
    # However, you must set it for any further virtual host explicitly.
    #ServerName www.example.com

    ServerAdmin webmaster@localhost
    DocumentRoot /var/www/html
     Alias /api_folder /var/www/html/api_folder
    <Directory /var/www/html/api_folder>
    Options Indexes FollowSymLinks
            AllowOverride All
            Require all granted
    Allow from all
     </Directory>

    # Available loglevels: trace8, ..., trace1, debug, info, notice, warn,
    # error, crit, alert, emerg.
    # It is also possible to configure the loglevel for particular
    # modules, e.g.
    #LogLevel info ssl:warn

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

    # For most configuration files from conf-available/, which are
    # enabled or disabled at a global level, it is possible to
    # include a line for only one particular virtual host. For example the
    # following line enables the CGI configuration for this host only
    # after it has been globally disabled with "a2disconf".
    #Include conf-available/serve-cgi-bin.conf


    Alias /static /home/my_user/spinner/static
      <Directory /home/my_user/spinner/static>
        Require all granted
      </Directory>

     Alias /media /home/my_user/spinner/media
      <Directory /home/my_user/spinner/static/media>
        Require all granted
      </Directory>

      <Directory /home/my_user/spinner/spinner>
        <Files wsgi.py>
          Require all granted
        </Files>
      </Directory>

    WSGIScriptAlias / /home/my_user/spinner/spinner/wsgi.py
    WSGIDaemonProcess spinner_app python-path=/home/my_user/spinner python-home=/home/my_user/venv_spinner
    WSGIProcessGroup spinner_app



</VirtualHost>

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

【问题讨论】:

  • 这到底是一个 Django 问题???
  • 那么你有什么建议?删除 Django 标签?

标签: php django ubuntu google-cloud-platform apache2


【解决方案1】:

您可能在 .htaccess 文件中遇到问题。请检查 .htaccess 文件一次。

确保您已启用 apache2 重写规则。 运行以下命令:

sudo a2enmod rewrite
sudo service apache2 restart

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2021-10-04
    • 2019-04-22
    • 2021-03-05
    • 2017-01-06
    • 2014-08-14
    • 2015-09-14
    • 2018-08-16
    相关资源
    最近更新 更多