nginx的新手,我正在尝试使用503代码设置自定义维护页面。我可以让页面显示,但我遗漏了一些内容并且没有应用css。当我将其视为传统网页时,它可以工作。我错过了什么?配置如下:
nginx.conf
user nginx;
worker_processes 4;
error_log /var/log/nginx/error.log info;
pid /var/run/nginx.pid;
events {
worker_connections 1024;
}
http {
server_names_hash_bucket_size 128;
# Set the max size for file uploads to 50Mb
client_max_body_size 50M;
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;
keepalive_timeout 65;
#gzip on;
underscores_in_headers on;
include /etc/nginx/conf.d/*.conf;
}
blah.conf
server {
listen 80;
root /var/www/blah-maintenance;
error_page 503 /503.html;
location / {
return 503;
}
location /503.html {
internal;
}
}
503.html
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN">
<html>
<head>
<meta http-equiv="content-type" content="text/html;charset=utf-8">
<link rel="stylesheet" type="text/css" href="/maint.css" />
</head>
<body>
<div class="container">
<h1>SYSTEM IS CURRENTLY UNDERGOING MAINTENANCE</h1>
<p class="blah">blah and blah-blah currently undergoing <b><u><font color="red">maintenance</font></u></b>.
<P class="blah">The system/s will be available as soon as possible. Please check back later.
<p class="blah">Thanks -
</div>
</body>
maint.css
/* CSS Document*/
/*Define the body element's color*/
body {
background: white url(black-floor-blah-wallpaper.jpg) no-repeat;
background-postion: center center;
}
h1 {
text-align:center;
font-size: 32pt;
color: White;
font-family: Helvetica, Geneva, Arial,
SunSans-Regular, sans-serif
}
/*This section is for links*/
a:link {
font-weight:normal;
color:Red
}
a:visited {
font-weight:normal;
color:Silver;
}
a:hover {
font-weight:bold;
color: White;
font-variant:small-caps;
}
/*This section is for a paragraph section*/
div.container {
display: tabel-cell;
vertical-align: middle;
postion: absolute;
top: 50%;
width: 100%;
}
p.blah {
text-align:center;
font-style:italic;
font-size:18px;
color: White;
}
blue {
color:#0000FF;
}
/*This section is for the image's black border.*/
img {
border-color: #000000;
border:thick;
border-style:ridge;`enter code here`
}
答案 0 :(得分:0)
浏览器对maint.css
的请求可能被nginx拦截并通过维护页面进行响应。您可以通过提取WebKit Inspector,Firebug或类似工具并查看“网络”选项卡上的流量来验证这一点。 /maint.css的响应应该返回CSS内容。如果它被拦截,您将会看到您的维护页面。
我通常为维护页面内联样式和资产,或者将整个请求重定向到另一个非维护区域以传递静态资产。您还可以为/maint.css编写重定向规则,但这可以很快扩散。 (&#34;哦等等,我们也需要这些图片。哦,我们还需要这些脚本......&#34;)