nginx 404、日志格式、https配置
2021-02-05 22:14
标签:mat form ssl load star mic ssi pen reload nginx -t 检查nginx配置文件格式是否正确 nginx静态资源存放路径: nginx配置文件存放路径: 当访问一个nginx 中不存在的路径时,就会报404错误 当访问http://192.168.115.128/ya 时,会出现以下错误页面 配置: 日志输出显示: nginx.key获取方式:openssl genrsa -out /etc/nginx/certs/nginx.key 2048 当访问www.ilinux.com时,就会跳转到https nginx 404、日志格式、https配置 标签:mat form ssl load star mic ssi pen reload 原文地址:https://blog.51cto.com/13159674/2504374
systemctl start nginx
systemctl enable nginx
ps -ef |grep nginx
nginx -s reload 重新加载配置,不用重启nginx进程
/usr/share/nginx/html/404.html 50x.html index.html
/etc/nginx/nginx.conf404错误配置
例如:
nginx.conf配置404的配置json格式输出日志
# log_format main ‘$remote_addr - $remote_user [$time_local] "$request" ‘
# ‘$status $body_bytes_sent "$http_referer" ‘
# ‘"$http_user_agent" "$http_x_forwarded_for"‘;
log_format json ‘{"remote_ip":"$remote_addr",‘
‘"remote_user":"$remote_user",‘
‘"time_local":"$time_local",‘
‘"request":"$request",‘
‘"status":"$status",‘
‘"body_sent":"$body_bytes_sent",‘
‘"referer":"$http_referer",‘
‘"agent":"$http_user_agent",‘
‘"forward":"$http_x_forwarded_for"}‘;
# access_log /var/log/nginx/access.log main;
access_log /var/log/nginx/access.log json;
HTTPS
server {
listen 80 default_server;
listen [::]:80 default_server;
server_name www.ilinux.com;
root /usr/share/nginx/html;
# Load configuration files for the default server block.
include /etc/nginx/default.d/*.conf;
location / {
rewrite (.*) https://www.ilinux.com$1 permanent;
}
error_page 404 /404.html;
location = /40x.html {
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
}
}
server {
listen 443 ssl;
ssl_protocols TLSv1.1 TLSv1.2;
ssl_ciphers HIGH:!aNULL:!MD5;
ssl_certificate /etc/nginx/certs/nginx.crt;
ssl_certificate_key /etc/nginx/certs/nginx.key;
ssl_session_cache shared:SSL:10m;
ssl_session_timeout 10m;
location / {
}
nginx.crt 获取方式:openssl req -new -x509 -key nginx.key -out nginx.cert -days 3650 -subj "/CN=www.ilinux.com"