侧边栏壁纸
博主头像
Eoser's page! 博主等级

@学习@生活@自己

  • 累计撰写 114 篇文章
  • 累计创建 29 个标签
  • 累计收到 0 条评论

目 录CONTENT

文章目录

Nginx 使用

eoser
2023-03-23 / 0 评论 / 0 点赞 / 0 阅读 / 0 字

安装

sudo apt-get install nginx

配置方法

直接修改nginx.conf

etcnginxnginx.conf

user www-data;
worker_processes auto;
pid runnginx.pid;
include etcnginxmodules-enabled*.conf;

events {
    worker_connections 768;
    # multi_accept on;
}

http {

    ##
    # Basic Settings
    ##

    sendfile on;
    tcp_nopush on;
    tcp_nodelay on;
    keepalive_timeout 65;
    types_hash_max_size 2048;
    # server_tokens off;

    # server_names_hash_bucket_size 64;
    # server_name_in_redirect off;

    include etcnginxmime.types;
    default_type applicationoctet-stream;

    ##
    # SSL Settings
    ##

    ssl_protocols TLSv1 TLSv1.1 TLSv1.2 TLSv1.3; # Dropping SSLv3, ref: POODLE
    ssl_prefer_server_ciphers on;

    ##
    # Logging Settings
    ##

    access_log varlognginxaccess.log;
    error_log varlognginxerror.log;

    ##
    # Gzip Settings
    ##

    gzip on;

    # gzip_vary on;
    # gzip_proxied any;
    # gzip_comp_level 6;
    # gzip_buffers 16 8k;
    # gzip_http_version 1.1;
    # gzip_types textplain textcss applicationjson applicationjavascript textxml applicationxml applicationxml+rss textjavascript;

    ##
    # Virtual Host Configs
    ##

    include etcnginxconf.d*.conf;
    include etcnginxsites-enabled*;
    # include 绝对路径*.conf; #可以添加直接要导入的配置目录
}

#mail {
#   # See sample authentication script at:
#   # http://uiai.fun/wiki.nginx.orgImapAuthenticateWithApachePhpScript
# 
#   # auth_http localhostauth.php;
#   # pop3_capabilities "TOP" "USER";
#   # imap_capabilities "IMAP4rev1" "UIDPLUS";
# 
#   server {
#       listen     localhost:110;
#       protocol   pop3;
#       proxy      on;
#   }
# 
#   server {
#       listen     localhost:143;
#       protocol   imap;
#       proxy      on;
#   }
#}
在conf.d下创建配置文件

上面的配置中可以看出引入了这个目录: include etcnginxconf.d*.conf; 我们可以在这个目录下面直接创建配置文件,比如:

# etcnginxconf.dtest.conf
server {
    listen 80;
    server_name test.;
    location  {
        proxy_set_header HOST $host;
        proxy_set_header X-Forwarded-Proto $scheme;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_pass http://uiai.fun/127.0.0.1:80080;
    }
}
创建专门的nginx配置目录

也能导入自己的配置文件

http{
    ......
    include etcnginxconf.d*.conf;
    include etcnginxsites-enabled*;
    #导入自己的目录
    include homeeoserprojecttestnginx*.conf
}

加载配置

service nginx reload

Nginx 配置详细参数

配置文件结构
......             #全配置
events {         #events配置
   ......
}
http      #http配置
{
    ......   #http全局配置
    server        #server配置
    { 
        ......       #server全局配置
        location [PATTERN]   #location配置
        {
            配置
        }
    ......
    }
    ......
}
......
  • 1、全局块:配置影响nginx全局的指令。一般有运行nginx服务器的用户组,nginx进程pid存放路径,日志存放路径,配置文件引入,允许生成worker process数等。
  • 2、events块:配置影响nginx服务器或与用户的网络连接。有每个进程的最大连接数,选取哪种事件驱动模型处理连接请求,是否允许同时接受多个网路连接,开启多个网络连接序列化等。
  • 3、http块:可以嵌套多个server,配置代理,缓存,日志定义等绝大多数功能和第三方模块的配置。如文件引入,mime-type定义,日志自定义,是否使用sendfile传输文件,连接超时时间,单连接请求数等。
  • 4、server块:配置虚拟主机的相关参数,一个http中可以有多个server。
  • 5、location块:配置请求的路由,以及各种页面的处理情况
0

评论区