默认配置文件地址
/etc/nginx/sites-enabled.d/default.conf
配置50x与404页面
server {
listen 80 default_server;
listen [::]:80 default_server;
# SSL configuration
#
# listen 443 ssl default_server;
# listen [::]:443 ssl default_server;
#
# Note: You should disable gzip for SSL traffic.
# See: https://bugs.debian.org/773332
#
# Read up on ssl_ciphers to ensure a secure configuration.
# See: https://bugs.debian.org/765782
#
# Self signed certs generated by the ssl-cert package
# Don't use them in a production server!
#
# include snippets/snakeoil.conf;
# 默认网站根目录
root /var/www/html;
# 默认网站首页支持文件类型
# Add index.php to the list if you are using PHP
index index.html index.htm index.nginx-debian.html;
# 500页面
error_page 500 502 503 504 http://blog.wangboweb.site;
# 404页面
error_page 404 /404.html;
server_name _;
location = /50x.html {
root /var/www/html;
}
location = /404.html {
root /var/www/html;
}
location / {
# 从上之下存在优先级
# 禁止指定ip不可访问,12/200表示12到200的ip段都不可访问
deny 192.168.12.12/200;
# 允许访问ip
allow 192.168.12.32;
try_files $uri $uri/ =404;
}
# pass PHP scripts to FastCGI server
#
#location ~ \.php$ {
# include snippets/fastcgi-php.conf;
#
# # With php-fpm (or other unix sockets):
# fastcgi_pass unix:/var/run/php/php7.0-fpm.sock;
# # With php-cgi (or other tcp sockets):
# fastcgi_pass 127.0.0.1:9000;
#}
# deny access to .htaccess files, if Apache's document root
# concurs with nginx's one
#
#location ~ /\.ht {
# deny all;
#}
}
本地跳转,在/var/www/html建立名称为404.html的文件
error_page 404 /404.html;
location = /404.html {
root /var/www/html;
}
外链跳转
error_page 500 502 503 504 http://blog.wangboweb.site;
配置完成后需要重载配置文件
nginx -s reload