除错

Ubuntu Nginx 除错 Debug 常用指令

回传参数

location ~ \.php$ {
    return 200 $args; add_header Content-Type text/plain;
    return 200 $uri; add_header Content-Type text/plain;
    return 200 $document_root; add_header Content-Type text/plain;
    return 200 $request_uri; add_header Content-Type text/plain;
}
  • $args:get 参数(e.g. ?page=2)
  • $uri:网址路径(e.g. /tag/laravel)
  • $document_root:网页路径(e.g. /var/web/laravel/public)
  • $request_uri:完整请求 URI(/tag/laravel?page=2)

测试 site-enabled 设定

nginx -t

413 Request entity too large

Nginx 预设档案上传大小为 100M,可以修改设定值提高上传档案大小

sudo vim /etc/nginx/nginx.conf

打开 nginx.conf 后,在 http 设定值中加入 client_max_body_size 并修改上传档案大小

若没有此设定值可自行加入

http {
    client_max_body_size 100M;
}

could not build server_names_hash, you should increase server_names_hash_bucket_size: 64

在新增 Nginx 主机时,发现网址名称有过长的问题

$ systemctl status nginx.service

● nginx.service - A high performance web server and a reverse proxy server
   Loaded: loaded (/lib/systemd/system/nginx.service; enabled; vendor preset: enabled)
   Active: failed (Result: exit-code) since Thu 2019-03-07 08:28:21 UTC; 7s ago
  Process: 9595 ExecStop=/sbin/start-stop-daemon --quiet --stop --retry QUIT/5 --pidfile /run/nginx.pid (code=exited, status=0/SUCCESS)
  Process: 9827 ExecStartPre=/usr/sbin/nginx -t -q -g daemon on; master_process on; (code=exited, status=1/FAILURE)
 Main PID: 31527 (code=exited, status=0/SUCCESS)

Mar 07 08:28:21 tnl-dev systemd[1]: Starting A high performance web server and a reverse proxy server...
Mar 07 08:28:21 tnl-dev nginx[9827]: nginx: [emerg] could not build server_names_hash, you should increase server_names_hash_bucket_size: 64
Mar 07 08:28:21 tnl-dev nginx[9827]: nginx: configuration file /etc/nginx/nginx.conf test failed
Mar 07 08:28:21 tnl-dev systemd[1]: nginx.service: Control process exited, code=exited status=1
Mar 07 08:28:21 tnl-dev systemd[1]: Failed to start A high performance web server and a reverse proxy server.
Mar 07 08:28:21 tnl-dev systemd[1]: nginx.service: Unit entered failed state.
Mar 07 08:28:21 tnl-dev systemd[1]: nginx.service: Failed with result 'exit-code'.

此时可以到 /etc/nginx/nginx.confserver_names_hash_max_size 设定更高的数值

server_names_hash_max_size 512;
server_names_hash_max_size 1024;

设定完后重新启动 Nginx 就可以正常启动了

参考资料