【问题标题】:POST method returning 405 method not allowed on Apache production server - Symfony3 projectApache 生产服务器上不允许返回 405 方法的 POST 方法 - Symfony3 项目
【发布时间】:2018-01-17 19:53:23
【问题描述】:

此处描述的一般范围previous question

我设法让项目在本地运行得很好,之后我将项目发布到我雇主的生产服务器上,经过一些配置后它就上线了。但是,当我执行我在本地执行的 POST 方法时,我得到“405 方法不允许”。

  • 是路由问题吗?
  • 是配置问题吗?
  • 是权限问题吗?
  • 还有别的吗?

配置信息很大,我不知道如果我在这里发布会有什么安全风险,所以请问我你需要知道什么

我会发布我认为可以分享的内容:

文件:/etc/apache2/mods-available/userdir.conf

<IfModule mod_userdir.c>
    UserDir public_html
    UserDir disabled root

    <Directory /home/*/public_html>
            AllowOverride FileInfo AuthConfig Limit Indexes
            Options MultiViews Indexes SymLinksIfOwnerMatch IncludesNoExec
            <Limit GET POST OPTIONS>
                    Require all granted
            </Limit>
            <LimitExcept GET POST OPTIONS>
                    Require all denied
            </LimitExcept>
    </Directory>

    <Directory /var/www/html/pdf/web>
            AllowOverride FileInfo AuthConfig Limit Indexes
            Options MultiViews Indexes SymLinksIfOwnerMatch IncludesNoExec
            <Limit GET POST OPTIONS>
                    Require all granted
            </Limit>
            <LimitExcept GET POST OPTIONS>
                    Require all denied
            </LimitExcept>
    </Directory>

文件:/etc/apache2/sites-available/000-default.conf

<VirtualHost ******:80>
    ServerName ******
    DocumentRoot /var/www/html/pdf/web

    <Directory /var/www/html/pdf/web>
    AllowOverride All
    Order Allow,Deny
    Allow from All
    </Directory>

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

    RewriteEngine on
    RewriteCond %{SERVER_NAME} =*******
    RewriteRule ^ https://%{SERVER_NAME}%{REQUEST_URI} [END,NE,R=permanent]

文件:/etc/apache2/sites-enabled/000-default-le-ssl.conf

<IfModule mod_ssl.c>
   <VirtualHost *****:443>
    ServerName *****
    DocumentRoot /var/www/html/pdf/web

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

    SSLCertificateFile ********************
    SSLCertificateKeyFile *****************
    Include /etc/letsencrypt/options-ssl-apache.conf
 </VirtualHost>

来自 phpinfo():

  • 系统 Linux uvn-243-1.tll07.zonevs.eu 4.4.0-042stab123.9 #1 SMP Thu Jun 29 13:01:59 MSK 2017 x86_64
  • 服务器 API Apache 2.0 处理程序
  • Apache 版本 Apache/2.4.18 (Ubuntu)
  • 加载模块强>核心mod_so mod_watchdog http_core mod_log_config mod_logio mod_version mod_unixd mod_access_compat mod_alias中mod_auth_basic mod_authn_core mod_authn_file模块mod_authz_core mod_authz_host mod_authz_user mod_autoindex mod_deflate模块mod_dir mod_env mod_filter mod_mime prefork的mod_negotiation模块mod_php7 mod_rewrite的mod_setenvif mod_socache_shmcb mod_ssl的mod_status的 LI>

正如 Symfony Docs 所解释的:现在 /web 文件夹中的根文件夹

我的职能:

   /**
 * @Rest\Post("/mcPDF/")
 */
public function getDataAction(Request $request){
    // Change the path to your jar file location
    $jarfile = "~/java/mcpdf.jar";

    // Change the path to your prefered destination where the output file will be created
    $result = "~/pdf_output/output.pdf";

    $form = $request->get('form');
    $data = $request->get('data');

    if(is_null($data) || $data == ""){
        return new View('Data source not found', Response::HTTP_NO_CONTENT);
    }elseif(is_null($form) || $form == ""){
        return new View('Form source not found', Response::HTTP_NO_CONTENT);
    }

    $command = "java -jar $jarfile $form fill_form - output - < $data > $result";

    $result = exec($command, $output);

    // dump($result);
    exit;

    }

    /**
 * @Rest\Post("/mPDF/")
 */
public function createPDFAction(Request $request){
    $source = $request->get('source');
    if($source == ""){
        return new View('No Data found', Response::HTTP_NO_CONTENT);
    }
    $mpdfService = $this->get('tfox.mpdfport');
    $html = file_get_contents($source);
    $mpdf = $mpdfService->getMpdf();
    $mpdf->WriteHTML($html);
    $mpdf->Output();
    exit;

}

非常重要的更新 成功地在服务器内部进行了 cURL 调用,并且成功了!你认为它是邮递员的问题吗?我正在使用 POSTMAN 来测试方法 cURL 调用:

curl -d "source=pdf_input/tax-calculation.html" -X POST https://*****/app.php/mPDF/

curl -d "form=pdf_input/sample.pdf&data=pdf_input/sample.xfdf" -X POST https://*****/app.php/mcPDF/

【问题讨论】:

    标签: php apache symfony post lamp


    【解决方案1】:

    我不确定这是否是正确的方法,但我解决了我的问题:)

    原来我不得不将邮递员中的 POST 方法 url 从 http 更改为 https

    所以 API 现在工作正常!!

    【讨论】:

    • 同样对我有用。应该是因为在虚拟主机中配置了从 http 到 https 的重定向。无法真正解释它的想法。
    • 它也解决了我的问题。我忘了在我的网址开头添加 https://
    猜你喜欢
    • 2021-12-12
    • 1970-01-01
    • 1970-01-01
    • 2014-05-23
    • 2021-04-05
    • 2021-07-07
    • 2014-11-27
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多