AskOverflow.Dev

AskOverflow.Dev Logo AskOverflow.Dev Logo

AskOverflow.Dev Navigation

  • 主页
  • 系统&网络
  • Ubuntu
  • Unix
  • DBA
  • Computer
  • Coding
  • LangChain

Mobile menu

Close
  • 主页
  • 系统&网络
    • 最新
    • 热门
    • 标签
  • Ubuntu
    • 最新
    • 热门
    • 标签
  • Unix
    • 最新
    • 标签
  • DBA
    • 最新
    • 标签
  • Computer
    • 最新
    • 标签
  • Coding
    • 最新
    • 标签
主页 / user-348964

Madox's questions

Martin Hope
Madox
Asked: 2016-04-15 01:18:09 +0800 CST

Nginx 1.2.1 自定义404

  • 2

我正在尝试使用 nginx 自定义 404 错误。

首先在我的本地机器中,我将以下几行添加到默认站点:

 error_page 404 /custom_404.html;
    location = /custom_404.html {
            root /usr/share/nginx/html;
            internal;
    }

然后在 /usr/share/nginx/html 文件夹中,我创建了一个名为 custom_404.html 的 nes 文件。

然后我去了我的开发机器并尝试做同样的事情,但没有任何运气。

我注意到的一件事是,在本地我使用的是 1.9.3 版本,而在开发环境中使用的是 1.2.1 版本,而且 html forlder (/usr/share/nginx/html) 不存在。

最后一件事是,在开发中我使用 nginx 进行 django 应用程序,所以我的配置文件是这样的:

server {
listen 80;
server_name test.example.net;

# output compression saves bandwidth
gzip  on;
gzip_http_version 1.1;
gzip_vary on;
gzip_comp_level 6;
gzip_proxied any;
gzip_types text/plain text/css application/json application/x-javascript text/xml application/xml application/xml+rss text/javascript;

client_max_body_size 10M;

if ($http_user_agent ~* '(blackberry|
    iemobile|iphone|ipod|mobile|Mobile|
    nokia|opera\s+mini|smartphone|symbian|webOS)') {
    set $mobile on;
}

if ($http_user_agent ~* 'ipad'){
    set $mobile off;
}

if ($host = example.net) {
    rewrite ^(.*)$ http://www.example.net$1 permanent;
}

if ($uri = '/') {
    set $home_es on;
}

if ($http_referer ~* ^http://test.example.net){
    set $home_es off;
}

if ($home_es = on) {
    rewrite ^(.*)$ /es$1 permanent;
}

gzip_buffers 16 8k;
gzip_disable "MSIE [1-6].(?!.*SV1)";

# media - folder in uri for admin static files
location /newmedia/ {
    expires 30d;
    root /media/jumbo_project;
}
location /media/ {
    expires 30d;
    alias /home/jumbo/media/jumbo_project/newmedia/;
}
location /static/ {
    expires 30d;
    root /media/jumbo_project;
}

error_page   502 503 504 500 /50x.html;

location /50x.html {
    internal;
}

location / {
    proxy_pass  http://localhost:8000;
    proxy_set_header X-Real-IP $remote_addr;
    proxy_set_header Host $host;
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    proxy_read_timeout 60;
}

log_format log_time '$request_time $remote_addr - $remote_user [$time_local]  '
    '"$request" $status $body_bytes_sent '
    '"$http_referer" "$http_user_agent"';

access_log  /var/log/nginx/jumbo-wsgi.access.log log_time;
error_log   /var/log/nginx/jumbo-wsgi.error.log;

我已经用完了谷歌的结果来尝试,所以如果有人能给我一个线索来继续,那就太好了。

linux django nginx http-status-code-404 google-compute-engine
  • 3 个回答
  • 554 Views

Sidebar

Stats

  • 问题 205573
  • 回答 270741
  • 最佳答案 135370
  • 用户 68524
  • 热门
  • 回答
  • Marko Smith

    新安装后 postgres 的默认超级用户用户名/密码是什么?

    • 5 个回答
  • Marko Smith

    SFTP 使用什么端口?

    • 6 个回答
  • Marko Smith

    命令行列出 Windows Active Directory 组中的用户?

    • 9 个回答
  • Marko Smith

    什么是 Pem 文件,它与其他 OpenSSL 生成的密钥文件格式有何不同?

    • 3 个回答
  • Marko Smith

    如何确定bash变量是否为空?

    • 15 个回答
  • Martin Hope
    Tom Feiner 如何按大小对 du -h 输出进行排序 2009-02-26 05:42:42 +0800 CST
  • Martin Hope
    Noah Goodrich 什么是 Pem 文件,它与其他 OpenSSL 生成的密钥文件格式有何不同? 2009-05-19 18:24:42 +0800 CST
  • Martin Hope
    Brent 如何确定bash变量是否为空? 2009-05-13 09:54:48 +0800 CST
  • Martin Hope
    cletus 您如何找到在 Windows 中打开文件的进程? 2009-05-01 16:47:16 +0800 CST

热门标签

linux nginx windows networking ubuntu domain-name-system amazon-web-services active-directory apache-2.4 ssh

Explore

  • 主页
  • 问题
    • 最新
    • 热门
  • 标签
  • 帮助

Footer

AskOverflow.Dev

关于我们

  • 关于我们
  • 联系我们

Legal Stuff

  • Privacy Policy

Language

  • Pt
  • Server
  • Unix

© 2023 AskOverflow.DEV All Rights Reserve