nginx编译安装及添加上传、上传进度第三方模块

1.安装nginx所需依赖

sudo apt-get install build-essential

sudo apt-get install libtool

sudo apt-get update

sudo apt-get install libpcre3 libpcre3-dev

sudo apt-get install zlib1g-dev

sudo apt-get install openssl

2.上传文件

将nginx及upload、progress第三方库上传或下载至ubuntu服务器

上传文件可参考

Xshell 文件传输sz/rz

下载链接:
nginx:

http://nginx.org/en/download.html

upload:

https://github.com/fdintino/nginx-upload-module#upload_pass

progress:

https://www.nginx.com/resources/wiki/modules/upload_progress/

3. 解压上传的压缩包并进入nginx目录下

解压:tar zxvf FileName.tar.gz
压缩:tar zcvf FileName.tar.gz DirName

4.输入指令添加模块

./configure --prefix=/usr/local/nginx --with-http_ssl_module --with-http_gzip_static_module --with-http_realip_module --add-module =‘upload模块目录’ --add-module = ‘progress模块目录’

参数说明:

–prefix 用于指定nginx编译后的安装目录

–add-module 为添加的第三方模块

–with…_module 表示启用的nginx模块,如此处启用了好几个模块

5.编译

make

6.安装

make install

7.启动指令

创建一个nginx软链接
ln -s /usr/local/nginx/sbin/nginx /usr/bin/nginx
查看配置文件是否正确:nginx -t
启动:nginx
重启:nginx -s reload
停止:nginx -s stop或者是通过kill nginx进程号
查看版本及编译参数:nginx –V

8.向nginx新增模块

在已安装的nginx上进行添加模块
1)备份配置文件
2)执行nginx -V查看已编译参数,./configure + 已编译参数 +添加新增模块;
3)make 编译完后,把objs中的nginx替换掉之前的nginx文件,然后重启nginx就行了;
如果执行下一步的install,会导致之前安装的nginx被覆盖,比如之前配置好的nginx.conf文件等

9.安装完成后,参考nginx.conf对nginx进行配置


user root;
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;
    client_max_body_size 100m;#设置上传文件的最大值
    upload_progress proxied 1m;#设置连接存放跟踪信息的最大值
    #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       10888;
        server_name  localhost;

	charset utf-8; 
        #charset koi8-r;

        #access_log  logs/host.access.log  main;
        #文件下载路径配置
        location /download {
		alias /usr/local/nginx/html/download;
		if ($request_filename ~* ^.*?\.(txt|pdf|doc|xls)$){  
			add_header Content-Disposition "attachment;";
		}
		autoindex on;
		autoindex_localtime on;
		autoindex_exact_size off;
        }
	#网页部署
	location /cloud {
		alias /cloud_ui;
		index index.html;
	}
	#上传进度部署
	location ^~ /progress{
		 report_uploads proxied;
	}
    #文件上传配置
	location /upload/ {
		upload_pass @test;
		upload_store /usr/local/nginx/tmp 1;
		upload_store_access user:r;
		upload_set_form_field $upload_field_name.name "$upload_file_name";
		upload_set_form_field $upload_field_name.content_type "$upload_content_type";
		upload_set_form_field $upload_field_name.path "$upload_tmp_path";
		upload_aggregate_form_field "$upload_field_name.md5" "$upload_file_md5";
		upload_aggregate_form_field "$upload_field_name.size" "$upload_file_size";
		upload_pass_form_field "^.*$";
		upload_cleanup 400 404 499 500-505;
		track_uploads proxied 30s;
	}
    #上传文件接口转发
	location @test{
		proxy_pass http://localhost:8080;
	}



        #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;
        }

        # proxy the PHP scripts to Apache listening on 127.0.0.1:80
        #
        #location ~ \.php$ {
        #    proxy_pass   http://127.0.0.1;
        #}

        # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
        #
        #location ~ \.php$ {
        #    root           html;
        #    fastcgi_pass   127.0.0.1:9000;
        #    fastcgi_index  index.php;
        #    fastcgi_param  SCRIPT_FILENAME  /scripts$fastcgi_script_name;
        #    include        fastcgi_params;
        #}

        # deny access to .htaccess files, if Apache's document root
        # concurs with nginx's one
        #
        #location ~ /\.ht {
        #    deny  all;
        #}
    }


    # 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;
    #    }
    #}

}

参考链接:
https://blog.csdn.net/zlxtk/article/details/80995955
https://blog.csdn.net/qq_54947566/article/details/116327207

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
在 macOS 上安装 nginx第三方模块可以使用 Homebrew 包管理器来简化过程。以下是安装第三方模块的步骤: 1. 首先,确保您已经安装了 Homebrew。如果您还没有安装,可以在终端中运行以下命令来安装 Homebrew: ``` /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)" ``` 2. 安装 nginx。在终端中运行以下命令来使用 Homebrew 安装 nginx: ``` brew install nginx ``` 3. 找到您想要安装第三方 nginx 模块。您可以通过在搜索引擎上搜索或访问模块的官方网站来找到合适的模块。 4. 下载并解压第三方模块的源代码。将源代码解压到一个您可以方便访问的位置。 5. 进入解压后的模块源代码目录,并使用 `./configure` 命令配置编译选项。在这个命令中,您可以通过添加 `--add-dynamic-module=/path/to/module` 来指定要安装模块。例如: ``` ./configure --add-dynamic-module=/path/to/module ``` 请将 `/path/to/module` 替换为您要安装模块的实际路径。 6. 完成配置后,运行 `make` 命令编译 nginx。 7. 编译完成后,在终端中运行以下命令将编译好的模块复制到 nginx模块目录: ``` cp objs/*.so /usr/local/Cellar/nginx/{version}/libexec/modules/ ``` 请将 `{version}` 替换为您当前安装nginx 版本号。 8. 在终端中运行以下命令启动 nginx: ``` brew services start nginx ``` 现在,您已经成功安装第三方模块,并且可以在 nginx 的配置文件中启用和配置它们。 请注意,安装第三方模块可能需要一些编译工具和依赖项。如果出现任何错误或依赖项缺失,您可能需要安装相应的工具和库。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值