Nginx安装
安装
tar zxvf nginx-1.2.9.tar.gz#解压nginxcdnginx-1.2.9#进入目录./configure--prefix=/opt/soft/nginx--with-http_stub_status_module--with-http_ssl_module--with-http_realip_module#配置安装模块make install#安装复制代码
--prefix:指定安装目录,默认的安装目录是/usr/local/nginx;
--with-http_ssl_module:安装https服务模块
启动
/opt/soft/nginx/sbin/nginx/opt/soft/nginx/sbin/nginx -s stop# fast shutdown/opt/soft/nginx/sbin/nginx -s quit# graceful shutdown/opt/soft/nginx/sbin/nginx -s reload# reloading the configuration file/opt/soft/nginx/sbin/nginx -s reopen# reopening the log files复制代码
设置开机自启动:
echo"/opt/soft/nginx/sbin/nginx -c /opt/soft/nginx/conf/nginx.conf">> /etc/rc.local复制代码
Nignx配置虚拟主机、反向代理、负载均衡
虚拟主机
主要配置server模块的 listen 和 server_name
基于域名
server {
listen 80;
server_name test.a.com;
location / {
proxy_pass http://192.168.0.1; #反向代理到其他站点
}
}
server {
listen 80;
server_name test.b.com;
location / {
proxy_pass http://192.168.0.2; #反向代理到其他站点
}
}
注意: 配置文件下载服务器
server{listen80;server_namefile.download.com;charsetutf-8;location~ ^/(.*)${add_headerContent-Disposition"attachment; filename=$1";#设置headeralias"C:/Robot_Download/$1";#文件的本地位置}}
基于端口
server {
listen 80;
server_name localhost;
alias /data/html/index.html; #也可使用root、location等方式指向静态资源
}
server {
listen 81;
server_name localhost;
root /data/html/index.html; #也可使用alias、location等方式指向静态资源
}
基于ip
server{listen100.100.100.100:80;server_namelocalho