1.安装gcc g++的依赖库
sudo apt-get install build-essential && sudo apt-get install libtool

2.安装pcre依赖库
sudo apt-get install libpcre3 libpcre3-dev

3.安装zlib依赖库
sudo apt-get install zlib1g-dev

4.安装ssl依赖库
sudo apt-get install openssl

安装nginx

#下载最新版本:
wget http://nginx.org/download/nginx-1.11.3.tar.gz
#解压:
tar -zxvf nginx-1.11.3.tar.gz
#进入解压目录:
cd nginx-1.11.3
#配置:
./configure --prefix=/usr/local/nginx 
#编辑nginx:
make

在编译步骤出现如下错误:

cc1: all warnings being treated as errors
objs/Makefile:460: recipe for target ‘objs/src/core/ngx_murmurhash.o’ failed
make[1]: *** [objs/src/core/ngx_murmurhash.o] Error 1
make[1]: Leaving directory ‘/home/wzj/tools/nginx/nginx-1.11.3’
Makefile:8: recipe for target ‘build’ failed
make: *** [build] Error 2

解决办法

找到对应的Maakefile文件,将gcc参数中的-Werror去掉。

我上面显示的是objs/Makefile文件,我打开看了下,将第三行的-Werror去掉就可以

 

 

#安装nginx:
sudo make install
#启动nginx:
sudo /usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf
注意:-c 指定配置文件的路径,不加的话,nginx会自动加载默认路径的配置文件,可以通过 -h查看帮助命令。
#查看nginx进程:
ps -ef|grep nginx

配置nginx

cd /usr/local/nginx/conf/

使用vim或nano编辑器在该目录下新建一个ihasy.conf文件输入以下内容:

upstream ihasy  {
    server 127.0.0.1:9001; #Tornado
}

## Start www.ihasy.com ##
server {
    listen 80;
    server_name  www.ihasy.com ihasy.com;

    #root   html;
    #index  index.html index.htm index.py index;

    ## send request back to Tornado ##
    location / {
        proxy_pass  http://ihasy;

        #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;
   }
}
## End www.ihasy.com ##

 

 

再使用vim或nano打开 /usr/local/nginx/conf/nginx.conf

nano /usr/local/nginx/conf/nginx.conf

在http下添加一行

include ihasy.conf

保存,重启nginx,即可实现反向代理。

 

版权声明:本文为duaimili原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。
本文链接:https://www.cnblogs.com/duaimili/p/10122925.html