PHP API 无法在 apache2 Ubuntu 服务器上使用 Django |谷歌云

标签 php django ubuntu google-cloud-platform apache2

我已经成功地在 上的 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_folderindex.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

最佳答案

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

确保您已启用 apache2 重写规则。
运行以下命令来做到这一点:

sudo a2enmod rewrite
sudo service apache2 restart

关于PHP API 无法在 apache2 Ubuntu 服务器上使用 Django |谷歌云,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59298700/

相关文章:

php - Symfony2 中的条件关系

php - CakePHP Acl 自动检查

django - 我如何暂时禁用 django 中的数据库完整性约束 - postgresql

django - Django 中的 login_required 装饰器

php - 使用 rocketter 部署到最近升级的 Ubuntu 16.04 box 时出错

php - Select2 未通过 POST 提交

php - 从 json 更改字符串颜色

Linux::Linux版本升级命令

python - 直接链接到 Wagtail modeladmin View

shell - 获取发送到电子邮件的回显 cron 文本