nginx配置
2015-10-14 00:00
579 查看
#nginx
#安装
#搭建nginx
首先在本机下载好所需要的软件。
pcre http://www.pcre.org/
zlib http://www.zlib.net/
openssl http://www.openssl.org/source/
nginx http://nginx.org/en/download.html
nginx安装好的目录在/usr/local/nginx
如果安装完 运行/usr/local/nginx/sbin/nginx出现:
解决办法是:
启动成功后 就可以尝试访问
#负载均衡配置
###nginx配置文件
修改配置之后
配置tomcat。配置不同的tomcat端口。上面配置的是两个tomcat 18080 18082
启动tocmat。
访问localhost.可以看到,请求分别分发到不同的tomcat中。
#安装
#搭建nginx
首先在本机下载好所需要的软件。
pcre http://www.pcre.org/
zlib http://www.zlib.net/
openssl http://www.openssl.org/source/
nginx http://nginx.org/en/download.html
apt-get install build-essential #ubuntu默认不支持c/c++编译。添加支持 apt-get install wget gcc make #安装wget、gcc、make #设置一个新的目录为nginx存放相关 mkdir -p /opt/local cd /opt/local #pcre tar -xvf /usr/download/pcre-8.36.tar.bz2 cd pcre-8.36 ./configure make make install #zlib tar -xvf /usr/download/nginx/zlib-1.2.8.tar.gz cd zlib-1.2.8/ ./configure make make install #openssl tar -zxvf /usr/download/nginx/openssl-0.9.8zg.tar.gz cd openssl-0.9.8zg/ ./config make make install #nginx tar -zxvf /usr/download/nginx/nginx-1.9.4.tar.gz cd nginx-1.9.4.tar.gz ./configure make make install
nginx安装好的目录在/usr/local/nginx
如果安装完 运行/usr/local/nginx/sbin/nginx出现:
error while loading shared libraries: libpcre.so.1: cannot open shared object file: No such file or directory
解决办法是:
32位系统 # ln -s /usr/local/lib/libpcre.so.1 /lib 64位系统 # ln -s /usr/local/lib/libpcre.so.1 /lib64
启动成功后 就可以尝试访问
#负载均衡配置
###nginx配置文件
#user nobody; #工作子进程数量 =cpu数量 or 2*cpu worker_processes 1; #错误日志路径 #error_log logs/error.log; #error_log logs/error.log notice; #error_log logs/error.log info; #pid logs/nginx.pid; events { #使用网络IO模型linux建议epoll,FreeBSD建议采用kqueue,window下不指定。 use epoll; #允许最大连接数 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; upstream localhost{ #weight 权重 值越大 被分配几率越大 server localhost:18080 weight=1; server localhost:18082 weight=1; } server { listen 80; server_name localhost; #charset koi8-r; #access_log logs/host.access.log main; location / { #root html; #index index.html index.htm; #请求转向真实地址 localhost为上面 upstream localhost的名字 proxy_pass http://localhost; proxy_set_header Host $host; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; } #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; # } #} }
修改配置之后
ps -ef |grep nginx #kill -9 #nginx -s stop nginx -s reload #重启 #然后重启
配置tomcat。配置不同的tomcat端口。上面配置的是两个tomcat 18080 18082
启动tocmat。
访问localhost.可以看到,请求分别分发到不同的tomcat中。
相关文章推荐
- nginx配置为系统服务
- 软件级负载均衡器(LVS/HAProxy/Nginx)的特点和对比
- nginx配置学习-nginx控制
- Nginx负载均衡配置实例详解
- Debian 7设备nginx周围环境、编译并安装和启动
- nginx后端服务健康检测
- nginx 部署thinkphp 做的东西, 配置 Pathinfo 模式,终于配好了
- 新装 nginx 容易报的错误Primary script unknown
- git和nginx安装
- 精通Nginx基础篇之基本操作和信号控制
- Nginx得知——流程模型(worker流程)
- 部署Nginx+Keepalived
- Linux/Nginx如何查看搜索引擎蜘蛛爬虫的行为
- nginx的优化配置
- Nginx1.8运行Laravel5的配置
- Nginx报错及解决方案汇总
- Nginx配置文件详细说明
- 性能测试之Nginx性能调优课程
- Nginx防蜘蛛爬虫处理
- nginx+php-fpm+mysql分离部署详解