一、Tomcat、Apache、Nginx三者区别
【Apache】、【Nginx】是HTTP服务器,其本身也是一种应用程序,运行在服务器之上,侦听某一tcp端口,浏览器便可以根据HTTP协议获取存在服务器上的文本、图片、视频、网页等静态资源。
【Tomcat】是应用服务器,是Servlet/JSP应用运行的容器。Tomcat能够动态生成资源返回至浏览器,而Apache、Nginx返回的资源是固定的(无论何时何人访问,返回的资源是相同的,即静态资源),Tomcat返回的动态资源不同时间、不同客户端返回的结果不同。
二、配置文件nginx.conf的结构
1、全局块,包含影响nginx整体运行的指令
2、events块,涉及的指令影响nginx服务器与用户的网络连接
3、http块,服务器配置最频繁的区域,包括http全局块和serve
/**#################全局块#################**/
#user nobody; //定义nginx运行的用户或用户组
worker_processes 1; //nginx并发处理进程的数量
#error_log logs/error.log;
#error_log logs/error.log notice;
#error_log logs/error.log info;
#pid logs/nginx.pid;
/**#####################events块####################**/events {
worker_connections 1024; //nginx每个进程的最大客户连接数
} //nginx最大客户连接数 = worker_processes*worker_connections
/**####################http块#######################**/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;
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 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;
# }
#}
}