下载安装包


wget https://nginx.org/download/nginx-1.18.0.tar.gz
wget http://downloads.sourceforge.net/project/pcre/pcre/8.35/pcre-8.35.tar.gz



安装依赖包,在线安装的,如果需要离线安装则根据操作系统内核下载相应的rpm,安装c++就会烦到飞起的,还有openssl也是依赖一大堆

yum install gcc-c++

# yum install -y pcre pcre-devel  #这个编译安装吧

yum install -y zlib zlib-devel

yum install -y openssl openssl-devel

安装pcre

tar zxf pcre-8.35.tar.gz

mv pcre-8.35 /usr/local

cd /usr/local/pcre-8.35

./configure

make && make install

安装nginx,--with-stream是让nginx可转发ftp,--user是指定启动用户,可用useradd -M -s /sbin/nologin nginx创建不可登陆nginx用户,也可为其它普通用户。

tar zxf nginx-1.18.0.tar.gz

mv pcre-8.35 /usr/local

cd /usr/local/nginx-1.18.0

./configure --prefix=/usr/local/nginx --with-http_stub_status_module --with-http_ssl_module --with-stream --with-stream_ssl_module --user=nginx --group=nginx

make

make install


添加快捷指令,这样随处可使用nginx

ln /usr/local/nginx/sbin/nginx /usr/bin/nginx

启动

nginx

查看版本

nginx -V

重启

nginx -s reload


解决跨域

vi /usr/local/nginx/conf/nginx.conf

http {

    server {
        listen       7778;
        server_name  bigScreen;
        location / {
            root   html/bigScreenTest;
            index  index.html index.htm;
        }
        location /bigscreen {
            rewrite ^/api/(.*)$ /screen/rest/v1/$1 break;
            proxy_pass http://your IP:your PORT;
        }
    }

}

代理sftp

stream {    
    upstream sftp{
        hash $remote_addr consistent; 
        server your IP:your PORT max_fails=3 fail_timeout=30s;
    }
    server {
        listen 7890;
        proxy_connect_timeout 30s; 
        proxy_timeout 30s; 
        proxy_pass sftp;
    }
}