2.安装(其中一种方法。没有成功) 2.1 安装pcre 1)https://ftp.pcre.org/pub/pcre/ 获取最新包 2)解压文件 tar -xzvf pcre-8.00.tar.gz 3)运行 ./configure 4)运行 make & make install 2.2 安装openssl(安装为成功,暂时不需要) 1)https://www.openssl.org/source/ 下载最新压缩包 2)解压文件 tar -xzvf 3)运行 ./config 4)运行make & make install(大概一分钟) 2.3 安装zlib 1)http://www.zlib.net/ 下载最新压缩包 2)解压文件 tar -xzvf zlib 3)运行./configure 4)运行make & make install(sudo)
2.4 另: 简单方法: sudo add-apt-repository ppa:nginx/stable sudo apt-get update sudo apt-get install nginx
该方法文件安装后路径: 应用config : /etc/nginx/
3.nginx配置
3.1 nginx.conf
样例:
user www-data;
worker_processes auto;
pid /run/nginx.pid;
include /etc/nginx/modules-enabled/*.conf;
events {
worker_connections 768;
# multi_accept on;
}
http {
##
# Basic Settings
##
sendfile on;
tcp_nopush on;
tcp_nodelay on;
keepalive_timeout 65;
types_hash_max_size 2048;
# server_tokens off;
# server_names_hash_bucket_size 64;
# server_name_in_redirect off;
include /etc/nginx/mime.types;
default_type application/octet-stream;
##
# SSL Settings
##
ssl_protocols TLSv1 TLSv1.1 TLSv1.2; # Dropping SSLv3, ref: POODLE
ssl_prefer_server_ciphers on;
##
# Logging Settings
##
access_log /var/log/nginx/access.log;
error_log /var/log/nginx/error.log;
##
# Gzip Settings
##
gzip on;
gzip_disable "msie6";
# gzip_vary on;
# gzip_proxied any;
# gzip_comp_level 6;
# gzip_buffers 16 8k;
# gzip_http_version 1.1;
# gzip_types text/plain text/css application/json application/javascript text/xml application/xml application/xml+rss text/javascript;
##
# Virtual Host Configs
##
include /etc/nginx/conf.d/*.conf;
include /etc/nginx/sites-enabled/*;
}
#mail {
# # See sample authentication script at:
# # http://wiki.nginx.org/ImapAuthenticateWithApachePhpScript
#
# # auth_http localhost/auth.php;
# # pop3_capabilities "TOP" "USER";
# # imap_capabilities "IMAP4rev1" "UIDPLUS";
#
# server {
# listen localhost:110;
# protocol pop3;
# proxy on;
# }
#
# server {
# listen localhost:143;
# protocol imap;
# proxy on;
# }
#}
配置说明: 1.worker_processes: 工作进程数量,一般设置为CPU数量 2.worker_connections表示每个工作进程的最大连接数 3.server{}块定义了虚拟主机 3.1 listener监听端口 3.2 server_name监听域名 3.3 location{} 是用来为匹配的URI进行配置的。 /{}是匹配所有的请求的 root指定对应uri的资源查找路径。相对路径 index指定首页index文件的名称,可以配置多个,以空格分开。 注:以上配置例子将http下的server配置到了配置文件中 default
3.2 mime.types 文件扩展名与文件类型映射表。 并且可以在default-type中指定默认值。
3.3 配置负载均衡
最简单的配置:
upstream hostname {
server 127.0.0.1:8080 max_fails=0 weight=1;
# server 192.168.1.9:8080 max_fails=0 weight=1;
}
server {
listen 80;
location / {
#hostname必须与upstream的名字相同
proxy_pass http://hostname;
proxy_redirect off;
proxy_set_header X-Real-IP $remote_addr;
}
3.4 配置热加载 server nginx reload