前言:本人主攻后端,简单了解运维,如有错误,请您指正
云服务器安装nginx安装nginx所需依赖yum -y install make zlib zlib-devel gcc-c++ libtool openssl openssl-devel解压nginx 在/usr/src目录会解压到/usr/local中tar –xvf pcre-8.37.tar.gz编译./configuremake && make install...
常用命令存放在/usr/local/nginx/sbin中./nginx -v ./nginx./nginx -s stop./nginx -s reload
反向代理nginx.conf 在/usr/local/nginx/conf目录中效果:访问 47.101.33.159:80 转发到47.101.33.159:8080修改server即可 server { listen 80;# server_name 47.101.33.159;# #charset koi8-r; #access_log logs/host.access.log main; location / { root html; proxy_pass http://47.101.33.159:8080;# index index.html index.htm; }效果:访问47.101.33.159:9000/mydir/mine.html 转发到47.101.33.159:8081/mydir/mine.html访问了在tomcat下webappmydir中的文件添加一个serverserver { listen 9000; server_name 47.101.33.159; location ~ /mydir/ { proxy_pass http://47.101.33.159:8081; }
负载均衡效果:访问47.101.33.159:80/mydrir/mine.html,第一次访问8080,第二次访问8081,轮转upstream myserver { server 101.43.85.67:8080; server 101.43.85.67:8081;} server { listen 80; server_name 101.43.85.67; #charset koi8-r; #access_log logs/host.access.log main; location / { root html; proxy_pass http://myserver; index index.html index.htm; }
动静分离效果:静态资源不通过tomcat进行访问,直接映射访问http://101.43.85.67/image/wechat.jpg 该图片地址为/mydata/image/wechat.jpg server { listen 80; server_name 101.43.85.67; #charset koi8-r; #access_log logs/host.access.log main; location /www/ { root /mydata/; index index.html index.htm; } location /image/ { root /mydata/; autoindex on; }