我在我的Nginx服务器上设置了任何域配置 – 以减少我打开新站点/域时所需的工作量.这个配置允许我简单地在/usr/share / Nginx / sites /中创建一个文件夹,其中包含域名/子域名,然后它才能正常工作.
server { # Catch all domains starting with only "www." and boot them to non "www." domain. listen 80; server_name ~^www\.(.*)$; return 301 $scheme://$1$request_uri; } server { # Catch all domains that do not start with "www." listen 80; server_name ~^(?!www\.).+; client_max_body_size 20M; # Send all requests to the appropriate host root /usr/share/Nginx/sites/$host; index index.html index.htm index.PHP; location / { try_files $uri $uri/ =404; } recursive_error_pages on; error_page 400 /errorpages/error.PHP?e=400&u=$uri&h=$host&s=$scheme; error_page 401 /errorpages/error.PHP?e=401&u=$uri&h=$host&s=$scheme; error_page 403 /errorpages/error.PHP?e=403&u=$uri&h=$host&s=$scheme; error_page 404 /errorpages/error.PHP?e=404&u=$uri&h=$host&s=$scheme; error_page 418 /errorpages/error.PHP?e=418&u=$uri&h=$host&s=$scheme; error_page 500 /errorpages/error.PHP?e=500&u=$uri&h=$host&s=$scheme; error_page 501 /errorpages/error.PHP?e=501&u=$uri&h=$host&s=$scheme; error_page 503 /errorpages/error.PHP?e=503&u=$uri&h=$host&s=$scheme; error_page 504 /errorpages/error.PHP?e=504&u=$uri&h=$host&s=$scheme; location ~ \.(PHP|html) { include /etc/Nginx/fastcgi_params; fastcgi_pass 127.0.0.1:9000; fastcgi_intercept_errors on; } }
但是,有一个问题我想解决,那就是当一个域名在sites目录中没有文件夹时,Nginx会抛出一个内部500错误页面,因为它无法重定向到/errorpages/error.PHP它不存在.