此处描述的一般范围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():
正如Symfony Docs所解释的:now / 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问题吗?我正在使用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/
答案 0 :(得分:1)
我不确定如果这是正确的方法,但我解决了我的问题:)
原来我必须将postman中的POST方法网址从http更改为https
所以API现在工作正常!!