💎一站式轻松地调用各大LLM模型接口,支持GPT4、智谱、星火、月之暗面及文生图 广告
user www www; ###user是主模块指令,定义Nginx运行的用户和用户组 worker_processes auto; ##worker_processes指令控制工作进程数:根据系统的配置进行设定,或者,可以将其设置为auto。 这样nginx会自动根据核心数为生成对应数量的worker进程。 error_log /home/wwwlogs/nginx_error.log crit; ###错误日志的地址。 pid /usr/local/nginx/logs/nginx.pid; ###里面存放的是当前nginx主进程的ID号 #Specifies the value for maximum file descriptors that can be opened by this process. ##指定此进程可以打开的最大文件描述符的值。(ulimit -n 可以查看最大值) worker_rlimit_nofile 51200; events { use epoll; ##epoll 是Linux内核中的一种可扩展IO事件处理机制,在具有大量应用程序请求时能够获得较好的性能。(nginx性能优化)使用epoll模型 worker_connections 51200; multi_accept on; ## events区域下accept_mutex参数将使每个可用的worker进程逐个接受新连接。 默认情况下,该标志设置为on } http { include mime.types; ##Nginx 会根据mime type定义的对应关系来告诉浏览器如何处理服务器传给浏览器的这个文件,是打开还是下载;( #文件扩展名与文件类型映射表) default_type application/octet-stream; ##默认情况下,让浏览器认为响应是普通的文件流,并提示用户下载文件。 server_names_hash_bucket_size 128; ##服务器名字的hash表大小,默认(32|64|128) client_header_buffer_size 32k; ##用于指定来自客户端请求头headerbuffer大小,对于大多数请求,1KB(默认)的缓冲区大小已经足够,如果自定义了消息头或有更大的cookie,可以增加缓冲区大小。这里设置为32KB large_client_header_buffers 4 32k; ##用来指定客户端请求中较大的消息头的缓存最大数量和大小, client_max_body_size 50m; ##设置客户端请求的最大文件字节数 sendfile on; ##endfile可以让Nginx在传输文件时直接在磁盘和tcp socket之间传输数据。如果这个参数不开启,会先在用户空间(Nginx进程空间)申请一个buffer,用read函数把数据从磁盘读到cache,再从cache读取到用户空间的buffer,再用write函数把数据从用户空间的buffer写入到内核的buffer,最后到tcp socket。开启这个参数后可以让数据不用经过用户buffer。 tcp_nopush on; ##防止网络阻塞,允许把httpresponse header和文件的开始放在一个文件里发布,作用是减少网络报文段的数量。(开启高效文件传输模式,将tcp_nopush和tcp_nodely两个指令设置为on,用于防止网络阻塞。) keepalive_timeout 60; ##keepalive_timeout 来指定 KeepAlive 的超时时间(timeout)。指定每个 TCP 连接最多可以保持多长时间。Nginx 的默认值是 75 秒,有些浏览器最多只保持 60 秒,所以可以设定为 60 秒。若将它设置为 0,就禁止了 keepalive 连接。 tcp_nodelay on; ##内核会等待将更多的字节组成一个数据包,从而提高I/O性能。 ###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 256k; ##临时写入文件的大小 gzip on; ##开启gzip压缩服务。 gzip_min_length 1k; ##设置最小的压缩值,单位为bytes。超过设置的min_length的值会进行压缩,小于的不压缩。 gzip_buffers 4 16k; ## 4 16k 代表以16k为单位,按照原始数据大小以16k为单位的4倍申请内存。 gzip_http_version 1.1; ### gzip压缩基于的http协议版本,默认就是HTTP 1.1 gzip_comp_level 2; ##压缩等级设置(1~9),1是最小压缩,速度也是最快的,9刚好相反,最大的压缩,速度是最慢的,消耗的cpu资源也多。 gzip_types text/plain application/javascript application/x-javascript text/javascript text/css application/xml application/xml+rss; ##压缩的类型 gzip_vary on; ##是否在http header中添加Vary: Accept-Encoding,建议开启,和http头有关系,加个vary头,给代理服务器用的,有的浏览器支持压缩,有的不支持,所以避免浪费不支持的也压缩,所以根据客户端的HTTP头来判断,是否需要压缩。 gzip_proxied expired no-cache no-store private auth; gzip_disable "MSIE [1-6]\."; ##禁用IE6的gzip压缩。 #limit_conn_zone $binary_remote_addr zone=perip:10m; ##If enable limit_conn_zone,add "limit_conn perip 10;" to server section. server_tokens off; ##隐藏nginx相关版本信息。 access_log off; server 默认端口80访问 http://192.169.1.109/admin { listen 80(自定义) default_server; #listen [::]:80 default_server ipv6only=on; server_name _; index index.html index.htm index.php; set $root /home/wwwroot/default/test1/public; 这里指向项目地址 root $root; #error_page 404 /404.html; # Deny access to PHP files in specific directory #location ~ /(wp-content|uploads|wp-includes|images)/.*\.php$ { deny all; } include enable-php.conf; location ~ \.php($|/) { root $root; fastcgi_pass 127.0.0.1:9000; fastcgi_index index.php; fastcgi_split_path_info ^(.+\.php)(.*)$; fastcgi_param PATH_INFO $fastcgi_path_info; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; include fastcgi_params; } location / { index index.html index.htm index.php; #autoindex on; if (!-e $request_filename) { rewrite ^(.*)$ /index.php?s=/$1 last; break; } } location /nginx_status { stub_status on; access_log off; } ####图片缓存时间设置 location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)$ { expires 30d; } ###JS和CSS缓存时间设置 location ~ .*\.(js|css)?$ { expires 12h; } ###通常证书验证需要访问.well-known ##增加配置来设置允许.well-known能访问 location ~ /.well-known { allow all; } ##禁止目录用的(例如一个文件或一个目录) 这是禁止 . 开头的隐藏文件及目录的 location ~ /\. { deny all; } access_log /home/wwwlogs/access.log; } include vhost/*.conf; } 然后项目访问可能要报错404,还需要修改一个文件配置,找到 usr/local/nginx/conf/fastcgi.conf 文件进入编辑指定open_basedir的路径呢如下: fastcgi_param REDIRECT_STATUS 200; fastcgi_param PHP_ADMIN_VALUE "open_basedir=/home/wwwroot/default/:/tmp/:/proc/"; 最后再重启nginx服务 service nginx restart