Nginx默认网站配置

目录

一、修改配置文件

二、创建404.html

三、创建用户

 四、模拟404

一、修改配置文件

当Nginx配置文件中有且只有一个Server的时候,该Server就被Nginx认为是默认网站,所有发给
Nginx服务器80端口的数据都会默认给该Server。

[root@003 ~]# vim /usr/local/nginx/conf/nginx.conf

user  www; # 创建一个www用户
worker_processes  2; # 本机有2核CPU

error_log  logs/error.log  info;

pid        logs/nginx.pid;


events {
    worker_connections  1024;
}


http {
    include       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  logs/access.log  main;

    sendfile        on;
    tcp_nopush     on;

    keepalive_timeout  5;

    #gzip  on;

    server {
        listen       80;
        server_name  localhost;
        

        # 创建一个404页面
        location / {
            root   html;
            index  index.html index.htm;
        }

        error_page  404              /404.html;
        location = /404.html {
                root html;
        }

        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   html;
        }
    }

二、创建404.html

[root@003 ~]# cd /usr/local/nginx/html/
[root@003 html]# vim 404.html

输入
sorry,not found!
hhhhhhhha

三、创建用户

[root@003 html]# useradd -s /sbin/nologin -r www
-r	建立系统帐号
-s 	指定用户登入后所使用的shell

[root@003 html]# killall -s HUP nginx
-s	用指定的进程号代替默认信号
HUP 重新加载(配置文件)进程

[root@003 html]# lsof -i :80

Nginx默认网站配置_第1张图片

 四、模拟404

正常进入:

Nginx默认网站配置_第2张图片

 404:

Nginx默认网站配置_第3张图片

 

你可能感兴趣的:(Linux应用软件部署,nginx,服务器,运维)