Rumah >pembangunan bahagian belakang >tutorial php >Nginx服务器基础配置详解 nginx 静态服务器 403 nginx做文件服务器 nginx配
Nginx配置整体认识
默认情况下,Nginx服务器配置文件都存放在安装目录Conf中,主配置文件名为nginx.conf 。其内容如下:
<code><span>#user nobody; #全局块</span> worker_processes <span>1</span>; <span>#error_log logs/<span>error</span>.log;</span><span>#error_log logs/<span>error</span>.log notice;</span><span>#error_log logs/<span>error</span>.log info;</span><span>#pid logs/nginx.pid;</span>events { <span>#events 块</span> worker_connections <span>1024</span>; } http { <span>#http块</span> include mime.types; <span>#http全局块</span> default_type application/octet-stream; <span>#log_format main '$remote_addr - $remote_user [$time_local] "$request" '</span><span># '$status $body_bytes_sent "$http_referer" '</span><span># '"$http_user_agent" "$http_x_forwarded_for"';</span><span>#access_log logs/access.log main;</span> sendfile on; <span>#tcp_nopush on;</span><span>#keepalive_timeout 0;</span> keepalive_timeout <span>65</span>; <span>#gzip on;</span> server { <span>#server块</span> listen <span>80</span>; <span>#server全局块</span> server_name localhost; <span>#charset koi8-r;</span><span>#access_log logs/host.access.log main;</span> location / { <span>#location块</span> root html; index index.html index.htm; } <span>#error_page 404 /404.html;</span><span># redirect server <span>error</span> pages to the static page /50x.html</span><span>#</span> error_page <span>500</span><span>502</span><span>503</span><span>504</span> /<span>50</span>x.html; location = /<span>50</span>x.html { <span>#location块</span> root html; } <span># proxy the PHP scripts to Apache listening on 127.0.0.1:80</span><span>#</span><span>#location ~ \.php$ { #location块</span><span># proxy_pass http://127.0.0.1;</span><span>#}</span><span># pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000</span><span>#</span><span>#location ~ \.php$ { #location块</span><span># root html;</span><span># fastcgi_pass 127.0.0.1:9000;</span><span># fastcgi_index index.php;</span><span># fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name;</span><span># include fastcgi_params;</span><span>#}</span><span># deny access to .htaccess files, <span>if</span> Apache's document root</span><span># concurs with nginx's one</span><span>#</span><span>#location ~ /\.ht {</span><span># deny all;</span><span>#}</span> } <span># another virtual host using mix of IP-, name-, and port-based configuration</span><span>#</span><span>#server { #server块</span><span># listen 8000;</span><span># listen somename:8080;</span><span># server_name somename alias another.alias;</span><span># location / { #location块</span><span># root html;</span><span># index index.html index.htm;</span><span># }</span><span>#}</span><span># HTTPS server</span><span>#</span><span>#server {</span><span># listen 443 ssl;</span><span># server_name localhost;</span><span># ssl_certificate cert.pem;</span><span># ssl_certificate_key cert.key;</span><span># ssl_session_cache shared:SSL:1m;</span><span># ssl_session_timeout 5m;</span><span># ssl_ciphers HIGH:!aNULL:!MD5;</span><span># ssl_prefer_server_ciphers on;</span><span># location / {</span><span># root html;</span><span># index index.html index.htm;</span><span># }</span><span>#}</span>}</code>
从配置文件我们可以总结如下
nginix.conf配置一共有三块组成:全局块、events块和http块。在http块中,包含多个server块,每个server块中又可以包含多个location块。
配置文件各模块意义
全局块
全局块是默认配置文件从开始到events模块之间的一部分内容。主要设置一下影响Nginx服务器整体运行的配置指令,该指令作用域是Nginix服务器全局。
通常包括运行Nginx服务器用户(组)、允许生产的worker process数、Nginix进程Pid存放路径、日志存放路径和类型以及配置文件引入等。
events块
events块涉及的指令主要影响Nginx服务器与用户的网络连接。常用配置有:
是否开启对多worker process下的网络连接进行序列化;
是否允许同时接受多个网络连接;
选择哪种事件模型处理连接请求;
每个worker process 可以同时支持的最大连接数等。
这一部分指令对Nginix服务器的性能影响较大,在实际配置中,应该根据实际情况,灵活调整。
http块
http块是Nginix服务器配置中重要部分。代理、缓存和日志定义绝大部分功能和第三方模块的配置都可以放到这个模块。http全局块中主要配置如下:
文件引入;
MIME-TYPE定义;
日志自定义;
是否使用sendfile传输文件;
连接超时时间;
单连接请求数上线等
server块
server块和“虚拟主机”概念有着密切联系。每个server块可以相当是一台虚拟主机。server块的作用域为本server块,不会影响到其他的server块。和http块相同,server块也可以包含自己的全局块,同时还可以包含多个location块。server全局块主要的两个配置如下:
虚拟主机的监听配置;
虚拟主机的名称或者ip配置
location块
每个server块可以包含多个location块,从严格意思来说,location其实是server是server块的一个指令。主要作用是,基与Nginx服务器接受到的请求字符串,对除虚拟主机名之外的字符串进行匹配,对特定的请求进行处理。地址定向、数据缓存和应答控制等功能都在这部分实现。
').addClass('pre-numbering').hide(); $(this).addClass('has-numbering').parent().append($numbering); for (i = 1; i ').text(i)); }; $numbering.fadeIn(1700); }); });以上就介绍了Nginx服务器基础配置详解,包括了nginx,服务器方面的内容,希望对PHP教程有兴趣的朋友有所帮助。