1、创建目录进入目录
mkdir /usr/local/nginx
cd /usr/local/nginx
2、安装gcc-c++编译器、安装openssl、安装pcre包、安装zlib包
yum install gcc-c++
yum install -y openssl openssl-devel
yum install -y pcre pcre-devel
yum install -y zlib zlib-devel
3、用wget命令下载nginx包,也可以自行去 https://nginx.org/download 进行下载
wget https://nginx.org/download/nginx-1.19.9.tar.gz
4、解压并进入nginx解压目录
tar -zxvf nginx-1.19.9.tar.gz
cd nginx-1.19.9
5、使用一下配置
./configure
6、编译安装,执行下方两个命令
make
make install
7、查询安装目录,进入安装目录中的sbin目录中
whereis nginx
cd /usr/local/nginx/sbin/
8、运行nginx,并且查看是否成功
./nginx
ps -ef|grep nginx
9、进入配置文件目录修改配置文件nginx.conf
cd /usr/local/nginx/conf/
vim nginx.conf
10、将80代理到9002端口,配置信息如下
server {
listen 80;
server_name localhost/minio/login;
location / {
proxy_pass http://localhost:9002;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
}
11、多个端口代理的配置信息为,nginx.conf为主配置,然后引用conf.d目录下的配置文件
nginx.conf中的内容
#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"';
log_format main '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"'
'$upstream_addr $upstream_response_time $request_time ';
access_log logs/access.log main;
sendfile on;
#tcp_nopush on;
#keepalive_timeout 0;
keepalive_timeout 65;
#gzip on;
gzip on;
gzip_min_length 1k;
gzip_buffers 4 16k;
gzip_http_version 1.0;
gzip_comp_level 2;
gzip_types text/plain application/x-javascript text/css application/xml;
gzip_vary on;
include conf.d/*.conf;
}
多端口的配置内容
server {
listen 928;
server_name minio.zym.com;
index index.html index.htm;
location / {
proxy_pass http://localhost:9002;
}
error_page 500 502 503 504 /50x.html;
location = ../50x.html {
root html;
}
location ~ .*\.(gif|jpg|jpeg|png|bmp|swf|svg)$ {
expires 24h;
proxy_pass http://localhost:9002;
}
location ~ .*\.(js|css)?$ {
expires 12h;
proxy_pass http://localhost:9002;
}
location ~ .*\.(html|htm)?$ { # 对HTML文件限制缓存
proxy_pass http://localhost:9002;
add_header Cache-Control no-cache; # 协商缓存
add_header Pragma no-cache;
}
}
server {
listen 928;
server_name mq.zym.com;
index index.html index.htm;
location / {
proxy_pass http://localhost:15672;
}
location ~ /js/tmpl/login.ejs? {
proxy_pass http://localhost:15672;
}
location /favicon.ico {
proxy_pass http://localhost:15672;
}
error_page 500 502 503 504 /50x.html;
location = ../50x.html {
root html;
}
location ~ .*\.(gif|jpg|jpeg|png|bmp|swf|svg)$ {
expires 24h;
proxy_pass http://localhost:15672;
}
location ~ .*\.(js|css)?$ {
expires 12h;
proxy_pass http://localhost:15672;
}
}