小诺文档中心 小诺文档中心
首页
小诺博客 (opens new window)
DevOps
云原生
技术
更多
网址导航
关于
  • 分类
  • 标签
  • 归档
GitHub (opens new window)

kevin

运维界的菜鸟
首页
小诺博客 (opens new window)
DevOps
云原生
技术
更多
网址导航
关于
  • 分类
  • 标签
  • 归档
GitHub (opens new window)
  • shell编程

  • 消息队列

  • web

    • nginx
    • nginx
    • Nginx_day01
    • Nginx_day02
    • Nginx_day03
    • Nginx_day04
    • Nginx_day05
    • nginx配置文件模板
      • php笔记
      • tomcat
    • ELK

    • 自动化运维

    • linux

    • DevOps
    • web
    xiaonuo
    2022-06-24
    目录
    php最简化配置
    wordpress配置
    mindoc配置
    nginx.conf
    proxy
    nginx配置模板

    nginx配置文件模板

    # php最简化配置
    server {
            listen       8080;
            server_name  w1.ops.com;
    
    
    access_log  /opt/nginx/logs/www_access.log;
    error_log   /opt/nginx/logs/www_error.log;
    
    
    location / {
                root   /opt/data;
                index index.php index.html index.htm;
    	}
     
    location ~ \.php$ {
                root           /opt/data;
                fastcgi_pass   127.0.0.1:9000;
                fastcgi_index  index.php;
                fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
                include        fastcgi_params;
            }
    
            error_page   500 502 503 504  /50x.html;
            location = /50x.html {
                root   html;
            }
    
    }
    
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    # wordpress配置
    server {
    
    
            listen       80;
            server_name  www.xnuo.top xnuo.top;	
    	rewrite ^(.*) https://$server_name$1 permanent;
    	
    	
    location /nginx {
    	stub_status on;
    	}
    }
    
    server {
    	server_name www.xnuo.top xnuo.top;	
    	listen 443 ssl;
    ssl_certificate /web/ssl/1_xnuo.top_bundle.crt;
    ssl_certificate_key /web/ssl/2_xnuo.top.key;
    ssl_ciphers "CHACHA20:GCM:HIGH:!DH:!RC4:!aNULL:!eNULL:!LOW:!3DES:!MD5:!EXP:!PSK:!SRP:!DSS";
    ssl_session_cache shared:SSL:10m;
    ssl_session_timeout 10m;
    
    
    
    location / {
                root   /web/wordpress;
                index index.php index.html index.htm;
    		try_files $uri $uri/ /index.php?$args;
    	if (-f $request_filename/index.html){
    rewrite (.*) $1/index.html break;
    }
    if (-f $request_filename/index.php){
    rewrite (.*) $1/index.php;
    }
    if (!-f $request_filename){
    rewrite (.*) /index.php;
    }
    
    rewrite /wp-admin$ $scheme://$host$uri/ permanent;
    	}
    
    
    access_log  /www/nginx/logs/www_access.log;
    error_log   /www/nginx/logs/www_error.log;
    
    # Add trailing slash to */wp-admin requests.
    
    location /image {
    		root /web/directory;
    	index index.php index.html index.htm;
    	}
    	 
    location ~ \.php$ {
                root           /web/wordpress;
                fastcgi_pass   127.0.0.1:9000;
                fastcgi_index  index.php;
                fastcgi_param  SCRIPT_FILENAME  /web$fastcgi_script_name;
                include        fastcgi.conf;
            }
    
    
            error_page   500 502 503 504  /50x.html;
            location = /50x.html {
                root   /web/html;
            }
    }
    
    
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    # mindoc配置
    server {
        listen       80;
    
        server_name  doc.xnuo.top;
    	rewrite (.*) https://doc.xnuo.top$1 permanent;	
    }
    
    server {
        listen  443 ssl;
        server_name doc.xnuo.top;
        add_header X-Content-Type-Options nosniff;
        ssl_certificate /web/ssl/doc_ssl.crt;
        ssl_certificate_key /web/ssl/doc_ssl.key;
    
    
        charset      utf-8;
        error_page 500 502 503 504 /50x.html;
        access_log  /www/nginx/logs/doc_access.log  main;
        error_log   /www/nginx/logs/doc_error.log;
        set $root_path '/web/mindoc';
        root $root_path;
        try_files $uri $uri/ @rewrite;
        index index.php index.html;
        location /50x.html {
           root /web/html;
        }
        #此处是关键
        location / {
            proxy_set_header X-Forwarded-For $remote_addr;
            proxy_set_header Host            $http_host;
            proxy_set_header   X-Forwarded-Proto $scheme;
            #此处配置 MinDoc 程序的地址和端口号
            proxy_pass http://127.0.0.1:8181/;
        }
        location ~* ^/(css|img|js|flv|swf|download)/(.+)$ {
            root $root_path;
            expires 30m;
        }
    }
    
    
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    # nginx.conf
    worker_processes  auto;
    
    user www;
    
    error_log logs/error.log error;
    events {
            accept_mutex on;
            multi_accept on;
            use epoll;
        worker_connections  10240;
    }
    
    
    
      worker_rlimit_nofile 65535;
    
    
    http {
    client_max_body_size 200M;
    
            gzip on;
            gzip_min_length 1k;
            gzip_buffers 4 32k;
            gzip_comp_level 4;
            gzip_types text/plain application/x-javascript text/css application/xml;
            gzip_vary on;
            server_tokens off;
    
    fastcgi_send_timeout 300;
    fastcgi_read_timeout 300;
    fastcgi_buffer_size 256K;
    fastcgi_buffers 4 256K;
    fastcgi_connect_timeout 300;
    
    
    proxy_buffer_size 256k;
    proxy_buffers 32 256k;
    proxy_busy_buffers_size 256k;
    
     log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
                         '$status $body_bytes_sent "$http_referer" '
                       '"$http_user_agent" "$http_x_forwarded_for"';
    
    sendfile        on;
    proxy_read_timeout 300s;
    keepalive_timeout  65;
    
     include       mime.types;
     default_type  application/octet-stream;
    
    #nginx vhosts config
            include conf.d/*.conf;
    
    }
    
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    # proxy
    upstream apachephp  {
        server ip:8080; #Apache
    }
     
    
    server {
        listen 80;
        server_name  www.redis.com.cn;
     
        access_log  logs/redis.access.log  main;
        error_log  logs/redis.error.log;
        root   html;
        index  index.html index.htm index.php;
     
        ## send request back to apache ##
        location / {
            proxy_pass  http://apachephp;
     
            #Proxy Settings
            proxy_redirect     off;
            proxy_set_header   Host             $host;
            proxy_set_header   X-Real-IP        $remote_addr;
            proxy_set_header   X-Forwarded-For  $proxy_add_x_forwarded_for;
            proxy_next_upstream error timeout invalid_header http_500 http_502 http_503 http_504;
            proxy_max_temp_file_size 0;
            proxy_connect_timeout      90;
            proxy_send_timeout         90;
            proxy_read_timeout         90;
            proxy_buffer_size          4k;
            proxy_buffers              4 32k;
            proxy_busy_buffers_size    64k;
            proxy_temp_file_write_size 64k;
       }
    }
    
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    # nginx配置模板
    user www www;
    worker_processes 8;
    
    #全局错误日志及PID文件
    error_log /usr/local/nginx/logs/nginx_error.log crit;
    
    pid /usr/local/nginx/nginx.pid;
    #Specifies the value for maximum file descriptors that can be opened by this process.
    worker_rlimit_nofile 65535;
    
    #工作模式及连接数上限
    events
    {
    use epoll;
    worker_connections 65535;
    }
    
    http
    {
    
    #设定mime类型
    include mime.types;
    default_type application/octet-stream;
    include /usr/local/nginx/conf/proxy.conf;
    #charset gb2312;
    
    #设定请求缓冲
    server_names_hash_bucket_size 128;
    client_header_buffer_size 32k;
    large_client_header_buffers 4 32k;
    client_max_body_size 8m;
    sendfile on;
    tcp_nopush on;
    keepalive_timeout 60;
    tcp_nodelay on;
    
    fastcgi_connect_timeout 300;
    fastcgi_send_timeout 300;
    fastcgi_read_timeout 300;
    fastcgi_buffer_size 64k;
    fastcgi_buffers 4 64k;
    fastcgi_busy_buffers_size 128k;
    fastcgi_temp_file_write_size 128k;
    gzip on;
    gzip_min_length 1k;
    gzip_buffers 4 16k;
    
    # gzip_http_version 1.0;
    # gzip_comp_level 2;
    # gzip_types text/plain application/x-javascript text/css application/xml;
    # gzip_vary on;
    
    ###禁止通过ip访问站点
    server{
    server_name _;
    return 404;
    }
    
    server
    {
    listen 80;
    server_name localhost;
    index index.html index.htm index.jsp;#设定访问的默认首页地址
    
    root /home/www/web/ROOT;#设定网站的资源存放路径
    
    #limit_conn crawler 20;
    
    #status的查看
    location /status {
    stub_status on;
    access_log /usr/local/nginx/logs/status.log;
    auth_basic "NginxStatus";
    }
    
    location ~ .*.jsp$ #所有jsp的页面均交由tomcat处理
    {
    index index.jsp;
    proxy_pass http://localhost:8080;#转向tomcat处理
    }
    
    location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)$ #设定访问静态文件直接读取不经过tomcat
    {
    expires 30d;
    }
    
    location ~ .*\.(js|css)?$
    {
    expires 1h;
    }
    
    #定义访问日志的写入格式
    log_format access '$remote_addr - $remote_user [$time_local] "$request" '
    '$status $body_bytes_sent "$http_referer" '
    '"$http_user_agent" $http_x_forwarded_for';
    access_log /usr/local/nginx/logs/localhost.log access;#设定访问日志的存放路径
    
    }
    }
    
    
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    Nginx_day05
    php笔记

    ← Nginx_day05 php笔记→

    最近更新
    01
    postgresql安装
    06-24
    02
    oracle笔记
    06-24
    03
    opengauss笔记
    06-24
    更多文章>
    Theme by Vdoing | Copyright © 2019-2025 kevin | 小诺运维
    • 跟随系统
    • 浅色模式
    • 深色模式
    • 阅读模式
    ×