如果我尝试访问网站根目录中未显示的内容,即http://example.com/unexisting.php,我会使用以下配置从我的自定义404页面获得正确的良好答案:< / p>
server_name example.com;
root /path/to/example;
index index.php;
error_page 404 /not_found.php;
location ~ index\.php
{
try_files $uri/index.php =404;
return 301 $scheme://$server_name/;
}
location ~ not_found\.php
{
root /path/to/example;
allow all;
internal;
fastcgi_intercept_errors off;
fastcgi_param SCRIPT_FILENAME $document_root/not_found.php;
include fastcgi_params;
}
location = /
{
try_files $uri/index.php @static;
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_param SCRIPT_FILENAME $document_root/index.php;
include fastcgi_params;
}
location ~ \.php$
{
try_files $uri $uri/ =404;
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_intercept_errors on;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
location @static
{
try_files $uri $uri/ =404;
expires max;
}
location /
{
try_files /something_non_existing @static;
}
如果我尝试从根文件夹中访问文件,i。即&#34; http://example.com/unexisting_dir/unexisting.php&#34;,404页面在屏幕上,但没有任何图形。因为在日志中有类似&#34; GET /unexisting_dir/images/some_image_for_404_page.png HTTP / 1.1&#34;并且nginx不返回任何内容,因为它有来自用户请求的错误基础。同时,我已经检查过$ document_root是否有正确的基础,所以php-fpm工作正常。
问题是如何让nginx忽略用户的URI,以便为未使用的嵌套(嵌入)目录服务404页面(不重定向和损害任何潜在的东西)?
非常感谢提前!
这是&#34; fastcgi_params&#34; (以防万一):
fastcgi_param QUERY_STRING $query_string;
fastcgi_param REQUEST_METHOD $request_method;
fastcgi_param CONTENT_TYPE $content_type;
fastcgi_param CONTENT_LENGTH $content_length;
fastcgi_param SCRIPT_NAME $fastcgi_script_name;
fastcgi_param REQUEST_URI $request_uri;
fastcgi_param DOCUMENT_URI $document_uri;
fastcgi_param DOCUMENT_ROOT $document_root;
fastcgi_param SERVER_PROTOCOL $server_protocol;
fastcgi_param HTTPS $https if_not_empty;
fastcgi_param GATEWAY_INTERFACE CGI/1.1;
fastcgi_param SERVER_SOFTWARE nginx/$nginx_version;
fastcgi_param REMOTE_ADDR $remote_addr;
fastcgi_param REMOTE_PORT $remote_port;
fastcgi_param SERVER_ADDR $server_addr;
fastcgi_param SERVER_PORT $server_port;
fastcgi_param SERVER_NAME $server_name;
fastcgi_param REDIRECT_STATUS 200;
fastcgi_pass unix:/var/run/php5-fpm.sock;
答案 0 :(得分:0)
这里的问题不是nginx。它正确返回not_found.php的输出
您需要确保输出包含图像的绝对路径,而不是HTML中的相对路径。 E.g。
<img src="notfound.jpg" />
而不是
<?php
error_reporting(0);
session_start();
include_once 'config.php';
if(!isset($_SESSION['user']))
{
header("Location: index.php");
}
$res=mysql_query("SELECT * FROM user WHERE user_id=".$_SESSION['user']);
$userRow=mysql_fetch_array($res);
$deptm = mysql_query("SELECT * FROM departments WHERE dep_ID = ".$userRow['department_id']."");
$deptment = mysql_fetch_array($deptm);
if(isset($_POST['send-btn']))
{
$recipient = $_POST['TO'];
$check = mysql_query("SELECT * FROM user WHERE faculty_number='$recipient'");
$rec = mysql_fetch_array($check);
if($userRow['position'] == 'Department Head')
{
if($rec['position'] != 'Dean' && $rec['position'] != 'Faculty Secretary')
{
$subject = $_POST['subject'];
$message = $_POST['message'];
$indicator = $_POST['indicator'];
$counter = $_POST['typ_cnt'];
$date = date('M-j');
/*$cnt=array();
$cnt=count($_POST['department']);
for($i=0;$i<$cnt;$i++)
{
$recipient=$_POST['department'][$i];*/
if($del=mysql_query("INSERT INTO memo(memo_date, iso, memo_subject, content, memo_sender) VALUES ('$date', 'UST:".$indicator." - ".$counter."/AY 2015-2016', '$subject','$message','".$userRow['faculty_number']."')"))
{
$getID = mysql_query("SELECT * FROM memo ORDER BY memo_ID DESC LIMIT 1");
$id = mysql_fetch_array($getID);
if($recipient=mysql_query("INSERT INTO recipients(id,type,iso,memo_sender,recipient_num,read_status,read_timestamp,acknowledgement,ack_timestamp,delete_status) VALUES ('".$id['memo_ID']."','memo','UST:".$indicator." - ".$counter."/AY 2015-2016','".$userRow['faculty_number']."', '$recipient', 'unread', '---', 'Not Acknowledged', '---', 'active')"))
{
?>
<script>alert('Memo Sent');</script>
<?php
}
else{
?>
<script>alert('Failed');</script>
<?php
}
}
else{
?>
<script>alert('Failed');</script>
<?php
}
//}
}else{
?>
<script>alert('Your recipient is not allowed');</script>
<?php
}
}else if($userRow['position'] == 'Dean')
{
$subject = $_POST['subject'];
$message = $_POST['message'];
$indicator = $_POST['indicator'];
$counter = $_POST['typ_cnt'];
$date = date('M-j');
/*$cnt=array();
$cnt=count($_POST['department']);
for($i=0;$i<$cnt;$i++)
{
$recipient=$_POST['department'][$i];*/
if($del=mysql_query("INSERT INTO memo(memo_date, iso, memo_subject, content, memo_sender) VALUES ('$date', 'UST:".$indicator." - ".$counter."/AY 2015-2016', '$subject','$message','".$userRow['faculty_number']."')"))
{
$getID = mysql_query("SELECT * FROM memo ORDER BY memo_ID DESC LIMIT 1");
$id = mysql_fetch_array($getID);
if($recipient=mysql_query("INSERT INTO recipients(id,type,iso,memo_sender,recipient_num,read_status,read_timestamp,acknowledgement,ack_timestamp,delete_status) VALUES ('".$id['memo_ID']."','memo','UST:".$indicator." - ".$counter."/AY 2015-2016','".$userRow['faculty_number']."', '$recipient', 'unread', '---', 'Not Acknowledged', '---', 'active')"))
{
?>
<script>alert('Memo Sent');</script>
<?php
}
else{
?>
<script>alert('Failed');</script>
<?php
}
}
else{
?>
<script>alert('Failed');</script>
<?php
}
//}
}
}
?>
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta content="IE=edge" http-equiv="X-UA-Compatible">
<meta content="width=device-width, initial-scale=1" name="viewport">
<meta content="" name="description">
<meta content="" name="author">
<title>Welcome - <?php echo $userRow['position']; ?></title>
<!-- Bootstrap Core CSS -->
<link href="bower_components/bootstrap/dist/css/bootstrap.min.css" rel=
"stylesheet"><!-- MetisMenu CSS -->
<link href="bower_components/metisMenu/dist/metisMenu.min.css" rel=
"stylesheet"><!-- Timeline CSS -->
<link href="dist/css/timeline.css" rel="stylesheet"><!-- Custom CSS -->
<link href="dist/css/sb-admin-2.css" rel="stylesheet">
<!-- Morris Charts CSS -->
<link href="bower_components/morrisjs/morris.css" rel="stylesheet">
<!-- Custom Fonts -->
<link href="bower_components/font-awesome/css/font-awesome.min.css" rel=
"stylesheet" type="text/css">
<!-- Bootstrap styling for Typeahead -->
<link href="dist/css/tokenfield-typeahead.css" type="text/css" rel="stylesheet">
<!-- Tokenfield CSS -->
<link href="dist/css/bootstrap-tokenfield.css" type="text/css" rel="stylesheet">
<!-- Docs CSS -->
<link href="docs-assets/css/pygments-manni.css" type="text/css" rel="stylesheet">
<link href="docs-assets/css/docs.css" type="text/css" rel="stylesheet">
<!-- HTML5 Shim and Respond.js IE8 support of HTML5 elements and media queries -->
<!-- WARNING: Respond.js doesn't work if you view the page via file:// -->
<!--[if lt IE 9]>
<script src="https://oss.maxcdn.com/libs/html5shiv/3.7.0/html5shiv.js"></script>
<script src="https://oss.maxcdn.com/libs/respond.js/1.4.2/respond.min.js"></script>
<![endif]-->
<script src="sendmemo.js" type="text/javascript"></script>
<script language="JavaScript">
function toggle(source) {
checkboxes = document.getElementsByName('department[]');
for(var i=0, n=checkboxes.length;i<n;i++) {
checkboxes[i].checked = source.checked;
}
}
</script>
</head>
<body>
<div id="wrapper">
<!-- Navigation -->
<nav class="navbar navbar-default navbar-static-top" style=
"margin-bottom: 0">
<div class="navbar-header">
<button class="navbar-toggle" data-target=".navbar-collapse"
data-toggle="collapse" type="button"><span class=
"sr-only">Toggle navigation</span> <span class=
"icon-bar"></span> <span class="icon-bar"></span> <span class=
"icon-bar"></span></button> <a class="navbar-brand" href=
"index.html">UNIVERSITY OF SANTO TOMAS - FACULTY OF MEDICINE
DOCUMENT MANAGEMENT SYSTEM</a>
</div>
<!-- /.navbar-header -->
<ul class="nav navbar-top-links navbar-right">
<li class="dropdown">
<a class="dropdown-toggle" data-toggle="dropdown" href=
"#"><i class="fa fa-bell fa-fw"></i> <i class=
"fa fa-caret-down"></i></a>
<ul class="dropdown-menu dropdown-alerts">
<li>
<a href="#">
<div>
<i class="fa fa-envelope-o fa-fw"></i> New
Message <span class=
"pull-right text-muted small">4 minutes
ago</span>
</div></a>
</li>
<li class="divider">
</li>
<li>
<a href="#">
<div>
<i class="fa fa-envelope fa-fw"></i> New
Message <span class=
"pull-right text-muted small">12 minutes
ago</span>
</div></a>
</li>
<li class="divider">
</li>
<li>
<a href="#">
<div>
<i class="fa fa-envelope fa-fw"></i> New
Message <span class=
"pull-right text-muted small">4 minutes
ago</span>
</div></a>
</li>
<li class="divider">
</li>
<li>
<a href="#">
<div>
<i class="fa fa-tasks fa-fw"></i> New Message
<span class="pull-right text-muted small">4
minutes ago</span>
</div></a>
</li>
<li class="divider">
</li>
<li>
<a href="#">
<div>
<i class="fa fa-upload fa-fw"></i> Server
Rebooted <span class=
"pull-right text-muted small">4 minutes
ago</span>
</div></a>
</li>
<li class="divider">
</li>
<li>
<a class="text-center" href="#"><strong>See All
Notifications</strong> <i class=
"fa fa-angle-right"></i></a>
</li>
</ul>
<!-- /.dropdown-alerts -->
</li>
<!-- /.dropdown -->
<li class="dropdown">
<a class="dropdown-toggle" data-toggle="dropdown" href=
""><i class="fa fa-user"></i>
<?php echo $userRow['first_name'];?> <?php echo $userRow['middle_name'];?> <?php echo $userRow['last_name'];?>
<b class="caret"></b></a>
<ul class="dropdown-menu">
<li>
<a><i class="fa fa-fw fa-user"></i>
<?php echo $userRow['position'];?></a>
</li>
<li class="divider">
</li>
<li>
<a href="changepass.php"><i class=
"fa fa-fw fa-wrench"></i> Change Password</a>
</li>
<li class="divider">
</li>
<li>
<a href="logout.php?logout"><i class=
"fa fa-fw fa-power-off"></i> Log Out</a>
</li>
</ul>
</li>
<!-- /.dropdown -->
</ul>
<div class="navbar-default sidebar">
<div class="sidebar-nav navbar-collapse">
<ul class="nav" id="side-menu">
<li>
<a href="<?php echo $_SESSION['home']?>"><i class=
"fa fa-home fa-fw"></i> Home</a>
</li>
<li>
<a href="sendmemo.php"><i class=
"fa fa-envelope-o fa-fw"></i> Send Memo</a>
</li>
<li>
<a href="index.html"><i class=
"fa fa-bar-chart-o fa-fw"></i> Reports<span class=
"fa arrow"></span></a>
<ul class="nav nav-second-level">
<li>
<a href="reports.php">List of
Acknowledgement</a>
</li>
<li>
<a href="index.html">Semestral Compliance
Report</a>
</li>
</ul>
<!-- /.nav-second-level -->
</li>
<li>
<a href="calendar.php"><i class=
"fa fa-table fa-fw"></i> Calendar</a>
</li>
<li>
<a href="inbox.php"><i class=
"fa fa-inbox fa-fw"></i> Inbox</a>
</li>
<li>
<a href="sent.php"><i class=
"fa fa-send-o fa-fw"></i> Sent</a>
</li>
<li>
<a href="allfiles.php"><i class=
"fa fa-files-o fa-fw"></i> All Files</a>
</li>
<?php
if($userRow['position'] = 'Dean' && $userRow['position'] = 'Faculty Secretary')
{ ?>
<li>
<a href="deanfolder.php"><i class="fa fa-folder fa-fw"></i> Folders</a>
</li>
<?php
}else if($userRow['position'] = 'Department Head')
{ ?>
<li>
<a href="departmentfolder.php"><i class="fa fa-folder fa-fw"></i> Folders</a>
</li>
<?php
}else if($userRow['position'] = 'Faculty')
{ ?>
<li>
<a href="facultyfolder.php"><i class="fa fa-folder fa-fw"></i> Folders</a>
</li>
<?php
}
?>
<li>
<a href="upload.php"><i class=
"fa fa-upload fa-fw"></i> Upload Document</a>
</li>
</ul>
</div>
<!-- /.sidebar-collapse -->
</div>
<!-- /.navbar-static-side -->
</nav>
<div id="page-wrapper">
<div class="row">
<div class="col-lg-12">
<h2 class="text-center">Send Memo</h2>
<ul class="nav nav-tabs nav-justified">
<li class="active"><a data-toggle="tab" href="#memo">Memo</a></li>
<li><a data-toggle="tab" href="#letter">Letter</a></li>
</ul>
<?php
switch($userRow['position'])
{
case 'Dean': $ind="A001-001";
break;
case 'Faculty Secretary': $ind="A002-002";
break;
case 'Department Head': $ind="A003-003";
break;
}
$result=mysql_query("SELECT count(*) as total from recipients WHERE memo_sender=".$userRow['faculty_number']);
$cntr=mysql_fetch_assoc($result);
$cnt = $cntr['total']+1;
$curYr = date('Y');
?>
<div class="tab-content">
<div id="memo" class="tab-pane fade in active">
<form method="post">
<div class="form-inline" role="form" ><br>
<label>ISO:</label>
<div class="form-group">
<label>UST:</label>
<input class="form-control" name="indicator" value="<?php echo $ind;?>" style="width:90px;"
type="text">
</div>
<div class="form-group">
<label>-</label>
<input type="text" class="form-control" name="typ_cnt" value="ME<?php echo $cnt;?>" style="width:60px;">
<label>/AY <?php echo $curYr;?> - <?php echo date('Y',strtotime('+1 year'));?> </label>
</div>
</div><br>
<div class="form-group">
<label>TO:</label>
<div class="input-group">
<input name="TO" type="textbox" class="form-control" id="tokenfield-typeahead" value="
<?php
if(isset($_POST['select-btn']))
{
$cnt=array();
$cnt=count($_POST['department']);
for($i=0;$i<$cnt;$i++)
{
$del_id=$_POST['department'][$i];
echo $del_id.",";
}
}
?> "/>
<span class="input-group-btn">
<button class="btn btn-warning" type="button" value="Departments" data-toggle="modal" data-target="#myModal">Department</button>
</span>
</div>
</div>
<div class="form-group">
<label for="subj">SUBJECT:</label>
<input class="form-control" name="subject"
type="text">
</div>
<br>
<div class="form-group">
<label for="message">Message:</label>
<textarea class="form-control" name="message" rows="10"></textarea>
</div>
<button type="submit" name="send-btn" class="btn btn-warning">Send</button>
</form>
<div class="modal fade" id="myModal" role="dialog">
<div class="modal-dialog">
<!-- Modal content-->
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal">×</button>
<h4 class="modal-title">Departments</h4>
</div>
<div class="modal-body">
<form method="post" action="sendmemo.php">
<div class="form-group">
<?php
$deptlist = mysql_query("SELECT * FROM departments");
while($dept = mysql_fetch_array($deptlist))
{
echo "<div class='checkbox'>";
echo "<label>";
echo "<input type='checkbox' name='department[]' value='".$dept['department_name']."' >" . $dept['department_name'];
echo "</label>";
echo "</div>";
}
?>
</div>
</div>
<div class="modal-footer">
<button type="submit" name="select-btn" class="btn btn-warning">Select</button>
</div>
</form>
</div>
</div>
</div>
</div>
<div id="letter" class="tab-pane fade">
<form method="post">
<div class="form-inline" role="form" ><br>
<label>ISO:</label>
<div class="form-group">
<label>UST:</label>
<input class="form-control" name="indicator" value="<?php echo $ind;?>" style="width:90px;"
type="text">
</div>
<div class="form-group">
<label>-</label>
<input type="text" class="form-control" name="typ_cnt" value="ME<?php echo $cnt;?>" style="width:60px;">
<label>/AY <?php echo $curYr;?> - <?php echo date('Y',strtotime('+1 year'));?> </label>
</div>
</div><br>
<div class="form-group">
<label>TO:</label>
<div class="input-group">
<input name="TO" type="textbox" class="form-control">
<span class="input-group-btn">
<button class="btn btn-warning" type="button" value="Departments" data-toggle="modal" data-target="#myModal">Department</button>
</span>
<div class="modal fade" id="myModal" role="dialog">
<div class="modal-dialog">
<!-- Modal content-->
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal">×</button>
<h4 class="modal-title">Departments</h4>
</div>
<div class="modal-body">
<div class="form-group">
<?php
$deptlist = mysql_query("SELECT * FROM departments");
while($dept = mysql_fetch_array($deptlist))
{
$dept_head = mysql_query("SELECT faculty_number FROM user WHERE position='Department Head' AND department_id='".$dept['dep_ID']."'");
echo "<div class='checkbox'>";
echo "<label>";
echo "<input type='checkbox' name='department[]' value='$dept_head' >" . $dept['department_name'];
echo "</label>";
echo "</div>";
}
?>
</div>
</div>
<div class="modal-footer">
<button type="submit" class="btn btn-warning" data-dismiss="modal">Select</button>
</div>
</div>
</div>
</div>
</div>
</div>
<div class="form-group">
<label for="subj">SUBJECT:</label>
<input class="form-control" name="subject" type="text">
</div>
<br>
<div class="form-group">
<label for="message">Message:</label>
<textarea class="form-control" name="message" rows="10"></textarea>
</div>
<button type="submit" name="send-btn" class="btn btn-danger">Send</button>
</form>
</div>
</div>
</div>
</div>
<!-- /#wrapper -->
<!-- jQuery -->
<script src="bower_components/jquery/dist/jquery.min.js"></script> <!-- Bootstrap Core JavaScript -->
<script src="bower_components/bootstrap/dist/js/bootstrap.min.js"></script> <!-- Metis Menu Plugin JavaScript -->
<script src="bower_components/metisMenu/dist/metisMenu.min.js"></script> <!-- Custom Theme JavaScript -->
<script src="dist/js/sb-admin-2.js"></script>
<script type="text/javascript" src="jquery-ui/jquery-1.9.1.js"></script>
<script type="text/javascript" src="jquery-ui/jquery-ui.js"></script>
<script type="text/javascript" src="dist/bootstrap-tokenfield.js" charset="UTF-8"></script>
<script type="text/javascript" src="docs-assets/js/scrollspy.js" charset="UTF-8"></script>
<script type="text/javascript" src="docs-assets/js/affix.js" charset="UTF-8"></script>
<script type="text/javascript" src="docs-assets/js/typeahead.bundle.min.js" charset="UTF-8"></script>
<script>
var engine = new Bloodhound({
<!--local: [{value: 'red'}, {value: 'blue'}, {value: 'green'} , {value: 'yellow'}, {value: 'violet'}, {value: 'brown'}, {value: 'purple'}, {value: 'black'}, {value: 'white'}, {value: 'jerome'}],
local: [<?php $suggest = mysql_query("SELECT * FROM user");
while($info = mysql_fetch_array($suggest))
{
echo "{value: '".$info['faculty_number']." (".$info['last_name'].", ".$info['first_name'].")'},";
}
?>],
datumTokenizer: function(d) {
return Bloodhound.tokenizers.whitespace(d.value);
},
queryTokenizer: Bloodhound.tokenizers.whitespace
});
engine.initialize();
$('#tokenfield-typeahead').tokenfield({
typeahead: [null, { source: engine.ttAdapter() }]
});
</script>
</body>
</html>
额外的正斜杠告诉浏览器从文档根目录而不是当前&#34;目录&#34;请求图像。浏览器已请求。