ubuntu安装openresty(nginx)[ubuntu部署]

来源:赵克立博客 分类: Linux 标签:nginx发布时间:2019-01-17 14:59:52最后更新:2019-06-01 11:11:50浏览:1864
版权声明:
本文为博主原创文章,转载请声明原文链接...谢谢。o_0。
更新时间:
2019-06-01 11:11:50
温馨提示:
学无止境,技术类文章有它的时效性,请留意文章更新时间,如发现内容有误请留言指出,防止别人"踩坑",我会及时更新文章

完整安装文档地址 https://openresty.org/cn/installation.html


安装前环境部署

打开ubuntu命令行,

apt-get install libpcre3-dev \
    libssl-dev perl make build-essential curl

如果安装时出现找不到包等错误,先更新下

apt-get update


安装openresty

下载openresty源码包

下载地址  https://openresty.org/cn/download.html

可以找到地址后直接使用下面命令下载

wget https://openresty.org/download/openresty-1.13.6.2.tar.gz

解压

tar -xzvf openresty-1.13.6.2.tar.gz

进入解压后的目录如下

image.png

配置编译项

先安装依赖包 zlib ,主要是开启gzip时用到的使用下面命令

sudo apt-get install zlib1g
sudo apt-get install zlib1g.dev

编译

./configure --prefix=/usr/local/openresty \
            --with-luajit \
            --without-http_redis2_module \
            --with-http_iconv_module \
            --with-http_postgres_module

如果遇到下面错误

image.png

使用下面命令安装

apt-get install libpq-dev

然后再次运行上面配置命令,如果运行成功后会在当前目录 里生成一个 makefile 文件,如下结构

image.png

命令行里会显示

image.png

编译

make

安装

make install

使用方法

注意安装完成后配置文件也在 /usr/local/openresty/nginx 下面

启动

/usr/local/openresty/nginx/sbin/nginx

停止

/usr/local/openresty/nginx/sbin/nginx -s stop

重启

/usr/local/openresty/nginx/sbin/nginx -s reload

检验nginx配置是否正确

/usr/local/openresty/nginx/sbin/nginx -t


设置环境变量

注意到上面命令太长啦,

在命令行使用 vim 编辑器添加环境变量路径,

vim /etc/profile

 i 键意思是插入 insert ,移动光标到文件最后面添加下面内容后按 esc 键退出编辑模式 ,再按 shift+:  进入命令模式输入 wq  回车保存退出


PATH=$PATH:/usr/local/openresty/nginx/sbin
export PATH

关闭命令行再打开就不用输入那么长的路径啦直接 nginx 加上后面的命令就可以


配置nginx.conf

http字段常用的配置

简单的配置nginx.conf 来移除服务器返回的一些头信息如下代码加到  http  段里就会移除所有的站点头信息

#移除响应头信息
more_clear_headers  'Server';
more_clear_headers 'X-Powered-By';
#反向代理时转发真实的ip地址
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $http_host;
proxy_set_header X-NginX-Proxy true;

配置php功能

前提是安装好啦 php-fpm7.2  功能,如果没有安装的话请参考文章  ubuntu安装php7.2,php-fpm[ubuntu部署]

location ~ \.php(.*)$  {
    fastcgi_pass   127.0.0.1:9000;
    fastcgi_index  index.php;
    fastcgi_split_path_info  ^((?U).+\.php)(/?.+)$;
    fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
    fastcgi_param  PATH_INFO  $fastcgi_path_info;
    fastcgi_param  PATH_TRANSLATED  $document_root$fastcgi_path_info;
    include        fastcgi_params;
}

配置https功能

server {
        listen       443 ssl;
        server_name  www.zhaokeli.com;
	ssl on;
	ssl_certificate      cert/1_www.xxxx.com_bundle.crt;
	ssl_certificate_key  cert/2_www.xxxx.com.key;
        #charset koi8-r;
        #access_log  logs/$host.access.log  main;
        location / {
			proxy_pass   http://www.xxxx.com:8888;
			index  index.html index.htm;
        }
}

证书放在 conf/cert 中上面的配置是使用啦反向代理,把请求重定向到后面的非 https 站点


微信号:kelicom QQ群:215861553 紧急求助须知
Win32/PHP/JS/Android/Python