这里我们安装稳定版
#### 新增nginx.repo文件
$ vi /etc/yum.repos.d/nginx.repo
# 内容如下
# 因为我服务器是centos 所以OS=centos
# OSRELEASE 自然也换成了7
[nginx]
name=nginx repo
baseurl=http://nginx.org/packages/centos/7/$basearch/
gpgcheck=0
enabled=1
$ yum list | grep nginx
$ yum install nginx
$ nginx -v
$ nginx -V
这里主要是适用于yum安装的nginx,大家可以参考这篇文章,也可以看我的博客
$ nginx -v
nginx version: nginx/1.12.2
$ nginx -V
--prefix=/etc/nginx --sbin-path=/usr/sbin/nginx --modules-path=/usr/lib64/nginx/modules --conf-path=/etc/nginx/nginx.conf --error-log-path=/var/log/nginx/error.log --http-log-path=/var/log/nginx/access.log --pid-path=/var/run/nginx.pid --lock-path=/var/run/nginx.lock --http-client-body-temp-path=/var/cache/nginx/client_temp --http-proxy-temp-path=/var/cache/nginx/proxy_temp --http-fastcgi-temp-path=/var/cache/nginx/fastcgi_temp --http-uwsgi-temp-path=/var/cache/nginx/uwsgi_temp --http-scgi-temp-path=/var/cache/nginx/scgi_temp --user=nginx --group=nginx --with-compat --with-file-aio --with-threads --with-http_addition_module --with-http_auth_request_module --with-http_dav_module --with-http_flv_module --with-http_gunzip_module --with-http_gzip_static_module --with-http_mp4_module --with-http_random_index_module --with-http_realip_module --with-http_secure_link_module --with-http_slice_module --with-http_ssl_module --with-http_stub_status_module --with-http_sub_module --with-http_v2_module --with-mail --with-mail_ssl_module --with-stream --with-stream_realip_module --with-stream_ssl_module --with-stream_ssl_preread_module --with-cc-opt='-O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector-strong --param=ssp-buffer-size=4 -grecord-gcc-switches -m64 -mtune=generic -fPIC' --with-ld-opt='-Wl,-z,relro -Wl,-z,now -pie'
$ cd /usr/local/src
wget https://nginx.org/download/nginx-1.12.2.tar.gz
wget https://github.com/openresty/headers-more-nginx-module/archive/v0.33.tar.gz
$ tar -zxvf nginx-1.12.2.tar.gz -C ../
$ tar -zxvf v0.33.tar.gz -C ../
openssl
扩展$ yum -y install pcre-devel openssl openssl-devel
header-more-nginx-module
模块/usr/local/headers-more-nginx-module,这个就是从github下载下来的扩展路径,因为yum安装的nginx貌似不能动态增加模块,,所以就安装yum安装的nginx编译命令,再编译一次
cd nginx-1.12.2/
// 在编译命令后面增加
./configure 上面的编译命令 --add-module=/usr/local/headers-more-nginx-module
$ make
$ make install
$ nginx -s quit
$ nginx -c /etc/nginx/nginx.conf
$ nginx -s reload
这个时候已经安装完毕了,但是你还没有用新nginx来启动,还有,老的nginx还在用着呢,如何无缝启动呢。
$ sudo make upgrade
user www www;
# 启动nginx /path/是配置路径
nginx -c /path/
# reload
nginx -s reload
# 停止nginx
nginx -s stop
# 重启nginx
nginx -s reopen
git clone https://github.com/alibaba/nginx-http-concat.git
这里因为每次都是重新编译,所以你一定要保证你之前的--add-module后面的模块一定存在,我个人建议这些nginx模块统一存放起来
//获得编译参数
nginx -V
// 增加编译参数
./configure 之前的编译参数 --add-module=/usr/local/src/nginx-modules/nginx-http-concat
$ make
$ make install
$ nginx -s quit
$ nginx -c /etc/nginx/nginx.conf
// 检查是否编译成功
$ nginx -V
location / {
concat on;//打开合并
concat_max_files 30;//最多合并30条资源
.......
}
//开始的写法
<link href="{{ asset('css/app.css') }}" rel="stylesheet">
<link href="{{ asset('css/style.css') }}" rel="stylesheet">
//合并之后的写法
<link href="/??css/app.css,css/style.css" rel="stylesheet" type="text/css">
这里一定要注意端口是443,同时proxy_pass后面是https
upstream 19media {
server 43.255.28.xxx:443; #19media
}
server {
listen 8002;
server_name localhost;
location / {
proxy_pass https://19media;
#Proxy Settings
proxy_redirect off;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_next_upstream error timeout invalid_header http_500 http_502 http_503 http_504;
proxy_max_temp_file_size 0;
proxy_connect_timeout 90;
proxy_send_timeout 90;
proxy_read_timeout 90;
proxy_buffer_size 4k;
proxy_buffers 4 32k;
proxy_busy_buffers_size 64k;
proxy_temp_file_write_size 64k;
}
}
代理HTTP的话,就80或者其他端口..然后https->http
sudo yum -y install pcre-devel openssl openssl-devel
这个主要是用于把我没有解析的server_name拦截起来
server {
listen 80 default_server;
listen 443;
server_name _;
access_log /var/log/nginx/hole_access.log main;
error_log /var/log/nginx/hole_error.log notice;
error_log /var/log/nginx/hole_error.log info;
return 404;
}
# centos
yum install httpd-tools
sudo mkdir /etc/nginx/openresty
sudo htpasswd -c -d /etc/nginx/openresty/netdata netdata
auth_basic "netdata";
auth_basic_user_file /etc/nginx/openresty/netdata
# 浏览器中使用
直接在浏览器中输入地址, 会弹出用户密码输入框, 输入即可访问
# 使用 wget
wget --http-user=magina --http-passwd=123456 http://xxxx/xxx.zip
# 使用 curl
curl -u magina:123456 -O http://res.yinnote.com/xxx.zip