做事难, 只是因为没去做! 本文记录在Ubuntu 16上安装Nginx步奏.
切换到指定目录
$ sudo su
# cd /usr/local/src/
# wget ftp://ftp.csx.cam.ac.uk/pub/software/programming/pcre/pcre-8.41.tar.gz
# cd pcre-8.41
# ./configure
# make
# make install
# cd /usr/local/src/
# wget http://zlib.net/zlib-1.2.11.tar.gz
# cd zlib-1.2.11
# ./configure
# make
# make install
# cd /usr/local/src
# wget https://www.openssl.org/source/openssl-1.0.1t.tar.gz
# tar -zxvf openssl-1.0.1t.tar.gz
# cd /usr/local/src
# wget http://nginx.org/download/nginx-1.12.1.tar.gz
# tar -zxvf nginx-1.12.1.tar.gz
# cd nginx-1.4.2
# ./configure \
--sbin-path=/usr/local/nginx/nginx \
--conf-path=/usr/local/nginx/nginx.conf \
--pid-path=/usr/local/nginx/nginx.pid \
--with-http_ssl_module \
--with-pcre=/usr/local/src/pcre-8.41 \
--with-zlib=/usr/local/src/zlib-1.2.11 \ --with-openssl=/usr/local/src/openssl-1.0.1t
# make
# sudo make install
# cd /usr/local/nginx
# ./nginx -t -c nginx.conf
// nginx: the configuration file /usr/local/nginx/nginx.conf syntax is ok
// nginx: configuration file /usr/local/nginx/nginx.conf test is successful
// -t 测试
// -c 指定配置文档位置
// 使用默认配置
# sudo /usr/local/nginx/nginx
// 使用指定配置
# ./nginx -c nginx.conf
# ps -ef|grep nginx
// 找到 master 进程
// nginx 33821 33820 0 12:06 pts/17 00:00:00 -bash
// root 33862 1 0 12:09 ? 00:00:00 nginx: master process /usr/local/nginx/nginx
// nobody 33863 33862 0 12:09 ? 00:00:00 nginx: worker process
// 这里主进程号: 33862
# kill -QUIT 33862
或者直接停止
# cd /usr/local/nginx
# ./nginx -s stop
// $ sudo ./nginx -s stop
# cd /usr/local/nginx
# ./nginx -s reload
# cd /usr/local/nginx
# ./nginx -v
// nginx version: nginx/1.12.1
# ./nginx -V
// nginx version: nginx/1.12.1
// built by gcc 5.4.0 20160609 (Ubuntu 5.4.0-6ubuntu1~16.04.4)
// built with OpenSSL 1.0.1t 3 May 2016
// TLS SNI support enabled
// configure arguments: --sbin-path=/usr/local/nginx/nginx --conf-path=/usr/local/nginx/nginx.conf --pid-path=/usr/local/nginx/npinx.pid --with-http_ssl_module --with-pcre=/usr/local/src/pcre-8.41 --with-zlib=/usr/local/src/zlib-1.2.11 --with-openssl=/usr/local/src/openssl-1.0.1t
root@nginx-virtual-machine:/usr/local/nginx#
# ./nginx -t
// 检查配置文件是否正确
// nginx: the configuration file /usr/local/nginx/nginx.conf syntax is ok
// nginx: configuration file /usr/local/nginx/nginx.conf test is successful
# cd /usr/local/nginx
# ./nginx -h
// 或者使用 ./nginx -?
// nginx version: nginx/1.12.1
// Usage: nginx [-?hvVtTq] [-s signal] [-c filename] [-p prefix] [-g directives]
//
// Options:
// -?,-h : this help
// -v : show version and exit
// -V : show version and configure options then exit
// -t : test configuration and exit
// -T : test configuration, dump it and exit
// -q : suppress non-error messages during configuration testing
// -s signal : send signal to a master process: stop, quit, reopen, reload
// -p prefix : set prefix path (default: /usr/local/nginx/)
// -c filename : set configuration file (default: /usr/local/nginx/nginx.conf)
// -g directives : set global directives out of configuration file
# cd /usr/local/nginx
// 测试配置文件
# ./nginx -t -c conf/new_nginx.conf
# kill -HUP [Nginx Master PID]
修改nginx.conf配置文件
http {
include mime.types;
# 配置第一个代理规则
server {
# 配置要监听的端口
listen 9180;
# 域名, 多个用空格' '隔开
server_name localhost 127.0.0.1;
# 代理所有 http://localhost:9180 请求
location / {
# 服务器所在位置
root /usr/local/tomcat/apache-tomcat-7.0.64;
index index.html index.htm index.jsp;
# tomcat 动态解析, 直接代理地址即可
proxy_pass http://localhost:8180;
}
}
# 配置第二个代理规则
server {
listen 9080;
server_name localhost;
location / {
root /usr/local/tomcat/apache-tomcat-7.0.64;
index index.html index.htm index.jsp;
proxy_pass http://localhost:8080;
}
}
}
http {
include mime.types;
server {
listen 8888;
server_name localhost;
location / {
root /usr/local/tomcat/apache-tomcat-7.0,64;
index index.html index.jsp;
proxy_pass http://localhost:8080;
}
}
server {
listen 9999;
server_name localhost;
location / {
root /usr/local/tomcat/apache-tomcat-7.0,64;
index index.html index.jsp;
proxy_pass http://localhost:8080;
}
}
}
location / {}
处理http {
server {
listen 9090;
server_name localhost;
# 匹配路径 http://[ip|localhost]:9090/t1
location /t1 {
root /usr/local/tomcat/apache-tomcat-7.0.64;
index index.html index.htm index.jsp;
proxy_pass http://localhost:8080/test;
}
# 匹配路径 http://[ip|localhost]:9090/t2
location /t2 {
root /usr/local/tomcat/apache-tomcat-7.0.64;
index index.html index.htm index.jsp;
proxy_pass http://localhost:8180/test;
}
# 其它路径, 如 /r1, /other1...
location / {
root /usr/local/tomcat/apache-tomcat-7.0.64;
index index.html index.htm index.jsp;
proxy_pass http://localhost:8180/test;
}
}
}
Upstream
实现负载均衡 http {
server {
listen 7777;
server_name localhost 127.0.0.1;
location / {
proxy_pass http://backend;
}
}
upstream backend {
server 192.168.1.128:8080;
server 192.168.1.128:8180;
}
}
$ sudo apt-get install openssh-server
nginx.pid
解决方案# ./nginx -s stop
// 或找到 master PID
// kill -QUIT [master PID]
// 重新启动
# ./nginx -c nginx.config
// $ sudo ./nginx -c nginx.conf
// 上传
# rz
// 下载
# sz [file_name]