在制作网站时遇到问题。我试图将POST请求发送到Node.js,但它返回错误499
。
Nginx配置:
server {
listen 80;
listen [::]:80;
server_name *********.com;
access_log /var/www/*********/log/access.log main;
error_log /var/www/*********/log/error.log;
root /var/www/*********.com/www;
index index.html;
if ( $http_x_forwarded_proto != 'https' ) {
return 301 https://$host$request_uri;
}
location / {
try_files $uri $uri/ =404;
}
location /admin/articles {
proxy_pass http://127.0.0.1:8888/;
}
}
完成Nginx的配置和权限(755个目录/ 644个文件):
user www-data;
worker_processes 2;
pid /run/nginx.pid;
events {
worker_connections 768;
# multi_accept on;
}
http {
##
# Basic Settings
##
sendfile on;
tcp_nopush on;
tcp_nodelay on;
keepalive_timeout 65;
types_hash_max_size 2048;
server_tokens off;
# server_names_hash_bucket_size 64;
# server_name_in_redirect off;
include /etc/nginx/mime.types;
default_type application/octet-stream;
##
# SSL Settings
##
ssl_protocols TLSv1 TLSv1.1 TLSv1.2; # Dropping SSLv3, ref: POODLE
ssl_prefer_server_ciphers on;
##
# Logging Settings
##
log_format main '$http_x_forwarded_for - $remote_user [$time_local] "$request" $status $body_bytes_sent "$http_referer" "$http_user_agent"';
access_log /var/log/nginx/access.log;
error_log /var/log/nginx/error.log;
##
# Gzip Settings
##
gzip on;
gzip_disable "msie6";
# gzip_vary on;
# gzip_proxied any;
# gzip_comp_level 6;
# gzip_buffers 16 8k;
# gzip_http_version 1.1;
# gzip_types text/plain text/css application/json application/javascript text/xml application/xml application/xml+rss text/javascript;
##
# Virtual Host Configs
##
include /etc/nginx/conf.d/*.conf;
include /etc/nginx/sites-enabled/*;
}
表单HTML:
<form method="POST" action="/admin/articles" enctype="multipart/form-data">
<div class="row row-sm-offset">
<div class="col-md-12" data-for="pageName">
<div class="form-group">
<label class="form-control-label mbr- fonts-style display-7" for="pageName-form1-ti">Nom de la page (ex : index.html)</label>
<input type="text" class="form-control" name="pageName" data-form-field="pageName" required="" id="pageName-form1-ti">
</div>
</div>
<div class="col-md-12" data-for="pageTitle">
<div class="form-group">
<label class="form-control-label mbr-fonts-style display-7" for="pageTitle-form1-ti">Titre de la page (ex : Acceuil)</label>
<input type="text" class="form-control" name="pageTitle" data-form-field="pageTitle" required="" id="pageTitle-form1-ti">
</div>
</div>
<div class="form-group col-md-12" data-for="pageDescription">
<label class="form-control-label mbr-fonts-style display-7" for="pageDescription-form1-ti">Description de la page (SEO)</label>
<textarea type="text" class="form-control" name="pageDescription" rows="7" data-form-field="pageDescription" id="pageDescription-form1-ti"></textarea>
</div>
<div class="col-md-5 multi-horizontal" data-for="pageDate">
<div class="form-group">
<label class="form-control-label mbr-fonts-style display-7" for="pageDate-form1-ti">Date de publication (ex : 17/10/19)</label>
<input type="text" class="form-control" name="pageDate" data-form-field="pageDate" id="pageDate-form1-ti">
</div>
</div>
<div class="col-md-6 multi-horizontal" data-for="pageImg">
<div class="form-group">
<label class="form-control-label mbr-fonts-style display-7" for="pageImg-form1-ti">Imagette de l'article (ex: image.jpg)</label>
<input type="file" class="form-control" name="pageImg" data-form-field="pageImg" id="pageImg-form1-ti">
</div>
</div>
</div>
<span class="input-group-btn">
<button id="submit-form" href="" type="submit" class="btn btn-primary btn-form display-4">Ajouter l'article</button>
</span>
</form>
脚本Node.js:
app.post('/admin/articles', function(request,response) {
console.log("Route : app.post /admin/articles");
var params = {
pageName : request.body.pageName,
pageTitle : request.body.pageTitle,
pageDescription : request.body.pageDescription,
pageDate : request.body.pageDate,
pageImg : request.body.pageImg
};
postManager.getLastIndex();
postManager.writePost(params);
});
访问日志:
"POST /admin/articles HTTP/1.1" 499 0 "https://**********.com/admin/admin.html?pageName=test.html&pageTitle=Module+de+test&pageDescription=dfsdfsdfsf&pageDate=11%2F10%2F1995&pageImg="
我尝试了一切!我不知道错误在哪里。 Nginx配置中可能存在问题。
如果您有想法,请随时分享!
谢谢。