POST method returning 405 method not allowed on Apache production server - Symfony3 project

浪尽此生 提交于 2020-01-07 03:42:52

问题


General Scope described here previous question

I managed to get the project working locally just fine, after that I published the project to my employer's production server and after some configuration it was live. However, I am getting "405 method not allowed" when I do the POST methods I was doing locally.

  • Is it a routing problem ?
  • Is it a config problem ?
  • Is it a permission problem ?
  • Something else ?

Config Information is large and I am not sure what would be a security risk if I post here, so Please ask me what you need to know

I will post what I think is OK to share:

File: /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>

File: /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]

File: /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>

From phpinfo():

  • System Linux uvn-243-1.tll07.zonevs.eu 4.4.0-042stab123.9 #1 SMP Thu Jun 29 13:01:59 MSK 2017 x86_64
  • Server API Apache 2.0 Handler
  • Apache Version Apache/2.4.18 (Ubuntu)
  • Loaded Modules core 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

As explained by Symfony Docs: the root folder in now /web folder

My Functions:

   /**
 * @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;

}

VERY IMPORTANT UPDATE Successfully did cURL calls inside the server and it worked ! Do you think its a POSTMAN problem ? I am using POSTMAN to test the methods cURL calls:

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/

回答1:


I am not sure If this is the right way but I solved my problem :)

Turns out that I had to change the POST method url in postman from http to https

So The API is now working fine !!



来源:https://stackoverflow.com/questions/45598901/post-method-returning-405-method-not-allowed-on-apache-production-server-symfo

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!