nginx + php + https 配置用例

3 篇文章 0 订阅
2 篇文章 0 订阅
启动服务的用户和组
user lighttpd lighttpd;

开多少进程
worker_processes 2;

错误日志
error_log /data/log/nginx/nginx_error/nginx_error.log crit;

pid
pid        /var/run/nginx.pid;

#Specifies the value for maximum file descriptors that can be opened by this process.
worker_rlimit_nofile 51200;

events
{
    use epoll;
    worker_connections 51200;
}

http
{
     开两 php-cgi 服务,端口连接方式速度快,socket方式稳定
     使用 lighttpd 的 spawn-fcgi 起的fast-cgi
     weight 是设置权重
    upstream phpfastcgi {
        server unix:/tmp/php-fastcgi0.sock weight=1;
        server unix:/tmp/php-fastcgi1.sock weight=1;
         server 127.0.0.1:8000   weight=1;
         server 127.0.0.1:8001   weight=1;
    }

     mime 类型 和 默认 header-type
    include       mime.types;
    default_type application/octet-stream;

     默认 header-charset
    charset utf-8;

     一些限制
    server_names_hash_bucket_size 128;
    client_header_buffer_size 32k;
    large_client_header_buffers 4 32k;
    client_max_body_size 8m;

     sendfile 应该是 lighttpd 的 sendfile 是一个意思
    sendfile on;
    tcp_nopush     on;

    keepalive_timeout 60;

    tcp_nodelay on;

     fastcgi 配置
    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
    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;

     #limit_zone crawler $binary_remote_addr 10m;

     定义日志格式
    log_format access '$remote_addr - $remote_user [$time_local] "$request" '
                        '$status $body_bytes_sent "$http_referer" '
                        '"$http_user_agent" $http_x_forwarded_for';

     定义一个虚拟机
    server
    {
         监听端口
        listen       80;
         虚拟机名
        server_name klpt-test.domain.com;
         如打开的是一个目录,默认的搜索文件的顺序
        index index.html index.htm index.php;
         虚拟机指向的路径
        root /data/www/klpt-test.domain.com/webroot;

         如果访问的路径不存在,那么rewrite给根目录的 index.php,路径以参数url来传递
        location / {
            index index.html index.php;

            if (-f $request_filename) {
                break;
            }

            if (!-f $request_filename) {
                rewrite ^/(.+)$ /index.php?url=$1 last;
                break;
            }
        }

         配置PHP
        location ~ \.php$ {
            fastcgi_pass   phpfastcgi;
            fastcgi_index index.php;
            fastcgi_param SCRIPT_FILENAME /data/www/klpt-test.domain.com/webroot$fastcgi_script_name;
            include        fastcgi_params;
        }

         图片缓存 30 天
        location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)$ {
            expires      30d;
        }
        
         js 和 css 缓存 1 小时
        location ~ .*\.(js|css)$ {
            expires     1h;
        }
    }

    server
    {
         定义的虚拟机监听端口是 443
        listen       443;
        server_name klpt.domain.com;
        index index.html index.htm index.php;
        root /data/www/klpt.domain.com/webroot;
        
         开启 ssl 服务
         命令 openssl req -new -x509 -nodes -out klpt-sqladmin.crt -keyout klpt-sqladmin.key
        ssl on;
        ssl_certificate /data/etc/nginx7/conf/klpt-sqladmin.crt;
        ssl_certificate_key /data/etc/nginx7/conf/klpt-sqladmin.key;
        ssl_session_timeout 5m;

        ssl_protocols SSLv2 SSLv3 TLSv1;
        ssl_ciphers ALL:!ADH:!EXPORT56:RC4+RSA:+HIGH:+MEDIUM:+LOW:+SSLv2:+EXP;
        ssl_prefer_server_ciphers   on;

         #limit_conn   crawler 20;
         如果访问的路径不存在,那么rewrite给根目录的 index.php,路径以参数url来传递
        location / {
            index index.html index.php;

            if (-f $request_filename) { 
                break; 
            }

            if (!-f $request_filename) {
                rewrite ^/(.+)$ /index.php?url=$1 last;
                break;
            }
        }

         php config
        location ~ \.php$ {
            fastcgi_pass   phpfastcgi;
            fastcgi_index index.php;
            fastcgi_param SCRIPT_FILENAME /data/www/klpt.domain.com/webroot$fastcgi_script_name;
             开启 https ,需要此配置
            fastcgi_param HTTPS on;
            include        fastcgi_params;
        }

         将静态文件缓存 30 天
        location ~ .*\.(gif|jpg|jpeg|png|bmp|swf|js|css)$ {
            expires      30d;
        }

         log
        access_log /data/log/nginx/nginx_access/nginx_klpt_access.log access;
    }

     静态服
    server
    {
        listen       80;
        server_name klpt-static.domain.com;
        index index.html index.htm;
        root /data/www/klpt-static.domain.com;

        location ~ .*\.(gif|jpg|jpeg|png|bmp|swf|js|css)$ {
            expires      30d;
        }
    }

    server
    {
        listen       443;
        server_name klpt-sqladmin.domain.com;
        index index.html index.htm index.php;
        root /data/www/klpt-sqladmin.domain.com;

        ssl on;
        ssl_certificate /data/etc/nginx7/conf/klpt-sqladmin.crt;
        ssl_certificate_key /data/etc/nginx7/conf/klpt-sqladmin.key;

        ssl_session_timeout 5m;

        ssl_protocols SSLv2 SSLv3 TLSv1;
        ssl_ciphers ALL:!ADH:!EXPORT56:RC4+RSA:+HIGH:+MEDIUM:+LOW:+SSLv2:+EXP;
        ssl_prefer_server_ciphers   on;

        location ~ \.php$ {
            fastcgi_pass   phpfastcgi;
            fastcgi_index index.php;
            fastcgi_param SCRIPT_FILENAME /data/www/klpt-sqladmin.domain.com$fastcgi_script_name;
             开启 https ,需要此配置
            fastcgi_param HTTPS on;
            include        fastcgi_params;
        }
    
        location ~ .*\.(gif|jpg|jpeg|png|bmp|swf|js|css)$ {
            expires      30d;
        }

        access_log /data/log/nginx/nginx_access/nginx_sqladmin_access.log access;
    }

}


http://hi.baidu.com/koocyton/item/4d6ec6f2fe3f3ccf531c268e

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
配置Nginx与MinIO一起使用HTTPS,您需要遵循以下步骤: 1. 安装和配置Nginx:首先,确保您已经在服务器上安装了Nginx,并且已经进行了基本的配置。您可以在Nginx的官方网站上找到适合您操作系统的安装说明。 2. 生成SSL证书:您需要为您的域名生成SSL证书,以便启用HTTPS。您可以使用自签名证书,或者从认证机构(例如Let's Encrypt)获取免费的SSL证书。 3. 配置Nginx反向代理:编辑Nginx配置文件(通常位于/etc/nginx/conf.d/目录下),创建一个新的服务器块来配置反向代理。以下是一个示例配置: ``` server { listen 80; server_name your_domain.com; location / { return 301 https://$host$request_uri; } } server { listen 443 ssl; server_name your_domain.com; ssl_certificate /path/to/your_ssl_certificate.crt; ssl_certificate_key /path/to/your_ssl_certificate_key.key; location / { proxy_set_header Host $host; proxy_set_header X-Real-IP $remote_addr; proxy_pass http://127.0.0.1:9000; # 这里的端口号和MinIO的配置有关 } } ``` 确保将`your_domain.com`替换为您的域名,`/path/to/your_ssl_certificate.crt`和`/path/to/your_ssl_certificate_key.key`替换为您的SSL证书和私钥的实际路径。 4. 重启Nginx:完成配置后,重新启动Nginx以使更改生效。您可以使用以下命令重启Nginx: ``` sudo service nginx restart ``` 现在,您的Nginx已经配置为使用HTTPS,并将请求代理到MinIO服务器。您可以通过访问`https://your_domain.com`来访问MinIO服务。 请注意,此配置仅适用于将MinIO与Nginx在同一台服务器上部署的情况。如果您将MinIO部署在不同的服务器上,请相应地修改Nginx配置中的`proxy_pass`指令。 希望对您有所帮助!如果您有任何其他问题,请随时提问。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值