002 Nginx 基础

核心目录

conf #配置文件
	nginx.conf # 默认的配置文件
	nginx.conf.default # 默认配置模板备份
	
html # 编译安装时,Nginx的默认站点目录
	50x.html #错误页面
	index.html # 默认首页
	
logs # nginx默认日志路径
	error.log # 错误日志
	nginx.pid # nginx进程号
	access.log #nginx访问日志
	
sbin # 程序目录
	nginx # 启动命令

常见命令

# 启动
./nginx

# 重启
./nginx -s reload

# 启动 加载指定配置
./nginx -c /usr/local/nginx/conf/nginx.conf

# 停止
./nginx -s stop

# 检查配置文件正确性
./nginx -t 

# 检查指定配置文件正确性
./nginx -t  -c /usr/local/nginx/conf/nginx.conf

基础配置

#user  nobody;
worker_processes  1;

# 全局的配置,注释的是默认
#error_log  logs/error.log;
#error_log  logs/error.log  notice;
#error_log  logs/error.log  info;
#pid        logs/nginx.pid;


events {
    use epoll; # linux加上这个, 采用epoll模式
    worker_connections  1024;
}


http {
    include       mime.types;
    default_type  application/octet-stream;

    # 默认的日志模版叫man
    #log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
    #                  '$status $body_bytes_sent "$http_referer" '
    #                  '"$http_user_agent" "$http_x_forwarded_for"';

    # 使用man日志模版
    #access_log  logs/access.log  main;

    # sendfile 开启高效传输
    sendfile        on;
    # 
    #tcp_nopush     on;

    #keepalive_timeout  0;
    keepalive_timeout  65; # 连接的超时时间

    #gzip  on; # 压缩,省带宽,耗性能

    # server [port] --> localtion[uri] -->
    server {
        listen       80;
        server_name  localhost; # 域名,可以写多个 空格隔开

        #charset koi8-r;

        #access_log  logs/host.access.log  main;

        # 访问 /, 先到html目录下找到index.html 找不到就找index.htm
        location / {
            root   html;
            index  index.html index.htm;
        }

        #error_page  404              /404.html;

        # redirect server error pages to the static page /50x.html
        #
        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   html;
        }

        # proxy the PHP scripts to Apache listening on 127.0.0.1:80
        #
        #location ~ \.php$ {
        #    proxy_pass   http://127.0.0.1; # 转发
        #}

        # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
        #
        #location ~ \.php$ {
        #    root           html;
        #    fastcgi_pass   127.0.0.1:9000;
        #    fastcgi_index  index.php;
        #    fastcgi_param  SCRIPT_FILENAME  /scripts$fastcgi_script_name;
        #    include        fastcgi_params;
        #}

        # deny access to .htaccess files, if Apache's document root
        # concurs with nginx's one
        #
        #location ~ /\.ht {
        #    deny  all; # 拒绝访问
        #}
    }


    # another virtual host using mix of IP-, name-, and port-based configuration
    #
    #server {
    #    listen       8000;
    #    listen       somename:8080;
    #    server_name  somename  alias  another.alias;

    #    location / {
    #        root   html;
    #        index  index.html index.htm;
    #    }
    #}


    # HTTPS server
    #
    #server {
    #    listen       443 ssl;
    #    server_name  localhost;

    #    ssl_certificate      cert.pem;
    #    ssl_certificate_key  cert.key;

    #    ssl_session_cache    shared:SSL:1m;
    #    ssl_session_timeout  5m;

    #    ssl_ciphers  HIGH:!aNULL:!MD5;
    #    ssl_prefer_server_ciphers  on;

    #    location / {
    #        root   html;
    #        index  index.html index.htm;
    #    }
    #}

}
已标记关键词 清除标记
相关推荐
©️2020 CSDN 皮肤主题: 撸撸猫 设计师:C马雯娟 返回首页