抛开SSL先不讲,针对使用WordPress搭建个人博客,Nginx的配置文件需要修改的地方不多。
不修改其实网站在运行时也不会有大问题,但总归有这有那的奇奇怪怪的小问题。
因此总结一下Nginx的配置文件的一些修改。
参考网站:
WordPress work with Nginx
Full Example Configuration
LNMP + WordPress 搭建个人网站教程:Debian下最新版本LNMP环境搭建以及安装WordPress建造你自己的个人网站
Nginx默认上传文件大小为1M,因此在上传超过1M的文件时会提示出错。
需要在nginx.conf文件里添加以下语句,大小可以任意更改。
http { ...... client_max_body_size 16m; }
如果不关闭这个的话,Nginx的error日志会定期的不断的抱怨没找到favicon.ico文件。
因此在conf.d/default.conf文件里添加以下语句。
Server { ...... location = /favicon.ico { log_not_found off; access_log off; } }
server { ...... location / { ...... try_files $uri $uri/ /index.php?$args; } }
server { ...... location = /robots.txt { allow all; log_not_found off; access_log off; } }
server { ...... location ~* \.(js|css|png|jpg|jpeg|gif|ico)$ { expires max; log_not_found off; } }
server { ...... location ~ \.user\.ini$ { deny all; } }
Server { ...... location ~ \.php$ { ...... fastcgi_intercept_errors on; fastcgi_buffers 16 16k; fastcgi_buffer_size 32k; } }
user www-data www-data; worker_processes 1; error_log /var/log/nginx/error.log warn; pid /var/run/nginx.pid; events { worker_connections 1024; } http { include /etc/nginx/mime.types; default_type application/octet-stream; log_format main '$remote_addr - $remote_user [$time_local] "$request" ' '$status $body_bytes_sent "$http_referer" ' '"$http_user_agent" "$http_x_forwarded_for"'; access_log /var/log/nginx/access.log main; sendfile on; #tcp_nopush on; client_max_body_size 16m; keepalive_timeout 65; gzip on; ssl_session_cache shared:SSL:10m; ssl_session_timeout 10m; include /etc/nginx/conf.d/*.conf; }
server { listen 80 default; server_name _; return 500; }
server { listen 80; server_name junjhome.com www.junjhome.com; #add_header Strict-Transport-Security "max-age=63072000; includeSubDomains; preload" always; return 301 https://$host$request_uri; }
server { listen 443 ssl; server_name junjhome.com www.junjhome.com; root /home/wordpress; add_header Strict-Transport-Security "max-age=63072000; includeSubDomains; preload" always; #add_header X-Frame-Options DENY; #add_header X-Content-Type-Options nosniff; ssl on; ssl_certificate /etc/letsencrypt/live/junjhome.com/fullchain.pem; ssl_certificate_key /etc/letsencrypt/live/junjhome.com/privkey.pem; ssl_protocols TLSv1 TLSv1.1 TLSv1.2; ssl_ciphers HIGH:!aNULL:!MD5; #charset koi8-r; access_log /var/log/nginx/host.access.log main; location = /favicon.ico { log_not_found off; access_log off; } location = /robots.txt { allow all; log_not_found off; access_log off; } location / { # root /usr/share/nginx/html; index index.php index.html index.htm; try_files $uri $uri/ /index.php?$args; } error_page 404 /404.html; # redirect server error pages to the static page /50x.html # error_page 500 502 503 504 /50x.html; location = /50x.html { # root /usr/share/nginx/html; } # proxy the PHP scripts to Apache listening on 127.0.0.1:80 # #location ~ \.php$ { # proxy_pass http://127.0.0.1; #} # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000 # location ~ \.php$ { # root html; fastcgi_pass unix:/run/php/php7.2-fpm.sock; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; include fastcgi_params; fastcgi_intercept_errors on; fastcgi_buffers 16 16k; fastcgi_buffer_size 32k; } location ~* \.(js|css|png|jpg|jpeg|gif|ico)$ { expires max; log_not_found off; } # deny access to .htaccess files, if Apache's document root # concurs with nginx's one # location ~ /\.ht { deny all; } location ~ \.user\.ini$ { deny all; } }