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 #重啓

 

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