编程技术分享平台

网站首页 > 技术教程 正文

3、Nginx的基本配置与优化(nginx常用优化配置的方式)

xnh888 2024-09-12 22:38:44 技术教程 38 ℃ 0 评论

1、Nginx的nginx.conf文件详解:

root@ha1 conf]# cat nginx.conf

#user nobody; 使用的用户和组 eg user nginx nginx

worker_processes 1; 指定工作衍生进程数(一般等于cpu的总核数的俩倍)

#error_log logs/error.log; 指定错误日志存放的路径

#error_log logs/error.log notice;

#error_log logs/error.log info;

#pid logs/nginx.pid; 指定pid存放的路径

events {

worker_connections 1024; 允许的连接数

}

http {

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; 是否开启gzip压缩

server {

listen 80;

server_name localhost;

#charset koi8-r;

#access_log logs/host.access.log main;

location / {

root html;

index index.html index.htm;

}

#error_page 404 /404.html;

# redirect server error pages to the static page /50x.html

#

error_page 500 502 503 504 /50x.html;

location = /50x.html {

root html;

}

# proxy the PHP scripts to Apache listening on 127.0.0.1:80

#

#location ~ \.php$ {

# proxy_pass http://127.0.0.1;

#}

# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000

#

#location ~ \.php$ {

# root html;

# fastcgi_pass 127.0.0.1:9000;

# fastcgi_index index.php;

# fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name;

# include fastcgi_params;

#}

# deny access to .htaccess files, if Apache's document root

# concurs with nginx's one

#

#location ~ /\.ht {

# deny all;

#}

}

# another virtual host using mix of IP-, name-, and port-based configuration

#

#server {

# listen 8000;

# listen somename:8080;

# server_name somename alias another.alias;

# location / {

# root html;

# index index.html index.htm;

# }

#}

# HTTPS server

#

#server {

# listen 443;

# server_name localhost;

# ssl on;

# ssl_certificate cert.pem;

# ssl_certificate_key cert.key;

# ssl_session_timeout 5m;

# ssl_protocols SSLv2 SSLv3 TLSv1;

# ssl_ciphers HIGH:!aNULL:!MD5;

# ssl_prefer_server_ciphers on;

# location / {

# root html;

# index index.html index.htm;

# }

#}

}

[root@ha1 conf]#

2、总结

通过nginx.conf文件的展示,大致可以看出,nginx.conf的配置文件结构主体结构主要由以下几部分构成:

3、下一节笔者将会详细介绍Nginx虚拟主机的配置,请关注哦

Tags:

本文暂时没有评论,来添加一个吧(●'◡'●)

欢迎 发表评论:

最近发表
标签列表