找回密码
 立即注册
搜索
热搜: 活动 交友 discuz
查看: 774|回复: 0

Nginx常用配置

[复制链接]

296

主题

38

回帖

1274

积分

管理员

积分
1274
发表于 2021-4-16 03:24:17 | 显示全部楼层 |阅读模式
#进程守护者:
user  nginx;

#错误日志
error_log  logs/error.log;

#pid进程信息:
pid        logs/nginx.pid;

#worker进程数:
worker_processes  1;

#每进程处理连接数:
worker_connections  1024;

#主配置区域结构:
http{
        #mime文件类型
        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  0;
        keepalive_timeout  65;
       
        #网页压缩传输       
        gzip  on;
       
        #第一台http虚拟主机配置
        server{
                #端口号
                listen       80;

                #网站域名
                server_name  localhost;

                #web字符集
                #charset koi8-r;

                #访问日志
                #access_log  logs/host.access.log  main;

                #匹配192.168.2.1或192.168.2.1/
                location / {
                        #设置网站根目录
                    root   html;

                    #设置默认首页
                    index  index.php index.html index.htm;
                }

                #设置404错误页面
                #error_page  404              /404.html;

                #设置50x错误页面
                error_page   500 502 503 504  /50x.html;
                location = /50x.html {
                    root   html;
                }

                #访问php文件时直接交给本机apache服务来处理
                location ~ \.php$ {
                    proxy_pass   http://127.0.0.1;
                }

                #请求php文件时交给php-fpm处理
                location ~ \.php$ {
                    fastcgi_index  index.php;
                    fastcgi_pass   127.0.0.1:9000;
                    fastcgi_param  SCRIPT_FILENAME $document_root$fastcgi_script_name;
                    include        fastcgi_params;
                }

                拒绝所有人访问.htaccess文件
                location ~ /\.ht {
                    deny  all;
                }
        }

        #第二台http虚拟主机配置
        server {
            listen       8000;
            listen       somename:8080;
            server_name  somename  alias  another.alias;

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

        #配置https虚拟主机
        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;
            }
        }
}


回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

QQ|Archiver|手机版|小黑屋|外汇论坛 ( 粤ICP备16021788号 )

GMT+8, 2024-5-18 15:28 , Processed in 0.074517 second(s), 19 queries .

Powered by Discuz! X3.5

© 2001-2024 Discuz! Team.

快速回复 返回顶部 返回列表