安装nginx
我安装的nginx版本是nginx-1.8.0
安装步骤:
apt-get install build-essential
apt-get install libtool
apt-get install gcc
wget https://sourceforge.mirrorservice.org/p/pc/pcre/pcre/8.35/pcre-8.35.tar.gz
tar -zxvf pcre-8.35.tar.gz
./configure
make
make install
wget https://svwh.dl.sourceforge.net/project/cbflib/External_Packages/zlib-1.2.8.tar.gz
tar -zxvf zlib-1.2.8.tar.gz
cd zlib-1.2.8
./configure
make
make install
wget https://ftp.openssl.org/source/old/1.0.1/openssl-1.0.1s.tar.gz
tar -zxvf openssl-1.0.1s.tar.gz
cd openssl-1.0.1s
./config
make
make install
wget https://master.dl.sourceforge.net/project/lonenmp/lnmpfiles/nginx/nginx-1.8.0.tar.gz
tar -zxvf nginx-1.8.0.tar.gz
cd nginx-1.8.0
./config
make
make install
在进行到最后一步时会报错,
src/core/ngx_murmurhash.c:37:11: error: this statement may fall through [-Werror=implicit-fallthrough=]
h ^= data[2] << 16;
在make时会有两个像上面这样的错误出现
解决方案:
cd /root/nginx-1.8.0/objs
vi Makefile
将第三行休改成这样:(原来的上面有一个-Werror)
CFLAGS = -pipe -O -W -Wall -Wpointer-arith -Wno-unused -g
之后再进行make和make isntall即可
执行init 6
重启ubuntu
启动nginx:/usr/local/nginx/sbin/nginx
然后访问ubuntu的80,如果出现nginx的默认页面,则安装成功
重启nginx
cd /usr/local/nginx/sbin
./nginx -s reload
检查配置语法
/usr/local/nginx/sbin/nginx -t
配置tomcat反向代理
编辑/usr/local/nginx/conf/nginx.conf
内容如下:http://127.0.0.1:51521;
是你的tomcat地址
#user nobody;
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 {
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;
server {
listen 80;
server_name localhost;
#charset koi8-r;
#access_log logs/host.access.log main;
#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;
}
location / {
proxy_pass http://127.0.0.1:51521;
index index.jsp index.html index.htm;
}
}
# 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;
# }
#}
}