linux安装nginx并配置tomcat代理

1.安装gcc-c++,pcre,zlib,openssl

yum install gcc-c++
yum install -y pcre pcre-devel
yum install -y zlib zlib-devel
yum install -y openssl openssl-devel

2.下载nginx安装包,nginx官网,download下,Stable version代表稳定版本,我这里选用的是1.18.0

wget --no-check-certificate --no-cookies https://nginx.org/download/nginx-1.18.0.tar.gz

3.解压安装包

tar -zxvf nginx-1.18.0.tar.gz

4.进入安装包,执行./configure及make命令

./configure --prefix=/usr/local/nginx
make
make install

5.进入目录/usr/local/nginx,默认配置文件相对路径位于conf/nginx.conf,编辑配置文件

worker_processes  4;#同cpu核数
error_log  logs/error.log;
events {
    worker_connections  65535;
}

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;
    keepalive_timeout  65;
    #tomcat代理配置
    server {
        listen       80;
        server_name  tomcat;
        location /t9/ {
            proxy_pass http://localhost:8080;
        }
    }
    server {
        listen       80;
        server_name  localhost;
        location / {
            root  html;
            index  index.html index.htm;
        }
        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   html;
        }
    }
}

6.nginx启动文件相对路径为sbin/nginx,直接运行启动,外网均可以通过80端口访问tomcat及nginx,成功

7.nginx常用命令

nginx -t #检查配置文件
nginx -s reload #重载配置文件
nginx -s stop #终止
nginx -s reopen #重启

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章