作者:陈伟明
联系 :  QQ 942923305 | 微信 toby942923305
E-mail: cwm.win@hotmail.com
==================================
服务器
操作系统: Ubuntu trusty14.04
nginx 版本: 1.10.1

==================================
修订时间:
15:09 2015-10-20 星期二
17:13 2015-10-23 星期五 修订错误
21:45 2016-06-09 星期四

=======================安装nginx前期准备==============================
安装依赖
# apt-get -y install libpcre3 libpcre3-dev zlib1g-dev libssl-dev build-essential libxml2 libxml2-dev  libxslt1.1 libxslt1-dev geoip-database libgeoip-dev  freetype* libgd2-xpm-dev

新建要入下载软件的目录
# mkdir /opt/soft
# cd /opt/soft
安装openssl (做ssl 443时会用到)
# wget http://www.openssl.org/source/openssl-1.0.2d.tar.gz
# tar -zxvf openssl-1.0.2d.tar.gz -C /usr/local/src/
# cd /usr/local/src/openssl-1.0.2d/
# ./config
# make
# make install

安装nginx
==========================nginx1.10.x安装============================
# cd /opt/soft
# curl -O http://nginx.org/download/nginx-1.10.1.tar.gz
# useradd www
# mkdir -p /var/log/nginx
# chown -R www:www /var/log/nginx
# tar xzvf nginx-1.10.1.tar.gz
# cd nginx-1.10.1
# mkdir -p /var/tmp/nginx/client
# chown -R www:www  /var/tmp/nginx/client
#./configure \
  --prefix=/usr/local/nginx\
  --conf-path=/etc/nginx/conf/nginx.conf \
  --error-log-path=/var/log/nginx/error.log \
  --http-log-path=/var/log/nginx/access.log \
  --pid-path=/var/run/nginx/nginx.pid  \
  --lock-path=/var/lock/nginx.lock \
  --user=www \
  --group=www \
  --with-openssl=/usr/local/src/openssl-1.0.2d \
  --with-http_realip_module\
  --with-http_sub_module \
  --with-http_dav_module \
  --with-http_ssl_module \
  --with-http_flv_module \
  --with-http_mp4_module \
  --with-http_stub_status_module \
  --with-http_gzip_static_module \
  --with-http_image_filter_module \
  --http-client-body-temp-path=/var/tmp/nginx/client/ \
  --http-proxy-temp-path=/var/tmp/nginx/proxy/ \
  --http-fastcgi-temp-path=/var/tmp/nginx/fcgi/ \
  --http-uwsgi-temp-path=/var/tmp/nginx/uwsgi \
  --http-scgi-temp-path=/var/tmp/nginx/scgi \
  --with-pcre \
  --with-file-aio

#make
#make install

说明:
--pid-path=/var/run/nginx/nginx.pid  \
这句要和
/etc/nginx/conf/nginx.conf 中的
pid        /var/run/nginx/nginx.pid;
要一样,要不然pid还是会以配置文件中的位置为标准

# vi /etc/init.d/nginx #编辑启动文件添加下面内容

-------------------------------
#!/bin/sh

### BEGIN INIT INFO
# Provides:          nginx
# Required-Start:    $local_fs $remote_fs $network $syslog
# Required-Stop:    $local_fs $remote_fs $network $syslog
# Default-Start:    2 3 4 5
# Default-Stop:      0 1 6
# Short-Description: starts the nginx web server
# Description:      starts nginx using start-stop-daemon
### END INIT INFO

PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
NAME=nginx
DESC=nginx

# Include nginx defaults if available
if [ -f /etc/default/nginx ]; then
  . /etc/default/nginx
fi

test -x $DAEMON || exit 0

set -e

. /lib/lsb/init-functions

test_nginx_config() {
  if $DAEMON -t $DAEMON_OPTS >/dev/null 2>&1; then
      return 0
  else
      $DAEMON -t $DAEMON_OPTS
      return $?
  fi
}

case "$1" in
  start)
      echo -n "Starting $DESC: "
      test_nginx_config
      # Check if the ULIMIT is set in /etc/default/nginx
      if [ -n "$ULIMIT" ]; then
        # Set the ulimits
        ulimit $ULIMIT
      fi
      start-stop-daemon --start --quiet --pidfile /var/run/$NAME.pid \
          --exec $DAEMON -- $DAEMON_OPTS || true
      echo "$NAME."
      ;;

stop)
      echo -n "Stopping $DESC: "
      start-stop-daemon --stop --quiet --pidfile /var/run/$NAME.pid \
          --exec $DAEMON || true
      echo "$NAME."
      ;;

restart|force-reload)
      echo -n "Restarting $DESC: "
      start-stop-daemon --stop --quiet --pidfile \
          /var/run/$NAME.pid --exec $DAEMON || true
      sleep 1
      test_nginx_config
      # Check if the ULIMIT is set in /etc/default/nginx
      if [ -n "$ULIMIT" ]; then
        # Set the ulimits
        ulimit $ULIMIT
      fi
      start-stop-daemon --start --quiet --pidfile \
          /var/run/$NAME.pid --exec $DAEMON -- $DAEMON_OPTS || true
      echo "$NAME."
      ;;

reload)
      echo -n "Reloading $DESC configuration: "
      test_nginx_config
      start-stop-daemon --stop --signal HUP --quiet --pidfile /var/run/$NAME.pid \
          --exec $DAEMON || true
      echo "$NAME."
      ;;

configtest|testconfig)
      echo -n "Testing $DESC configuration: "
      if test_nginx_config; then
        echo "$NAME."
      else
        exit $?
      fi
      ;;

status)
      status_of_proc -p /var/run/$NAME.pid "$DAEMON" nginx && exit 0 || exit $?
      ;;
  *)
      echo "Usage: $NAME {start|stop|restart|reload|force-reload|status|configtest}" >&2
      exit 1
      ;;
esac

exit 0

-----------------------------

# chmod 775 /etc/init.d/nginx   #赋予文件执行权限

# update-rc.d nginx defaults  #把nginx作为服务随机器启动

# service nginx start

把nginx工具目录加入到环境变量
# vi /etc/profile    最后加一行
PATH=$PATH:/usr/local/nginx/sbin
# source /etc/profile   使其生效

------------------------------------------------------------------------------
配置nginx

# mkdir /etc/nginx/conf/conf.d/
# vi /etc/nginx/conf/nginx.conf  内容如下:
-------------------
user              www;
worker_processes  4;
worker_cpu_affinity 00000001 00000010 00000011 00000100 ;
worker_rlimit_nofile 65535;

error_log  /var/log/nginx/error.log;  #日志
pid        /var/run/nginx.pid;

events {
    use epoll;
    worker_connections  65535;
    multi_accept on;
}

http {
    include      /etc/nginx/conf/mime.types;
    include      /etc/nginx/conf/gzip.conf;
    include      /etc/nginx/conf/cache-client.conf;

default_type  application/octet-stream;
    charset UTF-8;
    index        index.html index.htm ;

log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
              '$status $body_bytes_sent "$http_referer" '
              '"$http_user_agent" "$http_x_forwarded_for"';

types_hash_max_size 2048;             
 
    include /etc/nginx/conf/conf.d/*.conf;
}
-------------------

# vi /etc/nginx/conf/gzip.conf 内容如下:
----------------------

gzip on;
gzip_disable "msie6";
gzip_vary on;
gzip_proxied any;
gzip_comp_level 6;
gzip_min_length 1100;
gzip_buffers 16 8k;
gzip_http_version 1.1;
gzip_types text/plain text/css application/json application/x-javascript text/xml application/xml application/xml+rss text/javascript;

----------------------

# vi /etc/nginx/conf/cache-client.conf 内容如下:
----------------------
#frequently read cache
open_file_cache max=200000 inactive=20s;
open_file_cache_valid 30s;
open_file_cache_min_uses 2;
open_file_cache_errors on;

#client cache
client_max_body_size 200m;
client_body_buffer_size 128k;
client_header_buffer_size 32k;
large_client_header_buffers 4 32k;

#client timeout
sendfile          on;
tcp_nopush        on;
tcp_nodelay        on;
server_tokens      off;

----------------------

配置完成

================nginx1.10.x安装 结束===============

================配置odoo8与nginx结合 开始===============
对前odoo8 在 ubuntu14.04 是怎么安装的,可以参考前面的一篇文章 《odoo8.0 _Ubuntu14.04源码安装》
已经上传上了空间里,这里我就重复说了
前面一开始安装用的用户是www ,不是官方用的odoo ,这就为采用nginx作反代理,进行了平滑地过度。

生成ssl的证件和key

# mkdir /etc/nginx/ssl 
# cd /etc/nginx/ssl
# openssl genrsa -des3 -passout pass:odoo -out server.pass.key 2048    # pass:x 可以换成 pass:hkyejian##@  这样安全一些
# openssl rsa -passin pass:odoo -in server.pass.key -out server.key
# rm server.pass.key
# openssl req -new -key server.key -out server.csr  #这里要添加相关信息,自己按提示写一下就可以
# openssl x509 -req -days 3650 -in server.csr -signkey server.key -out server.crt  #指定证书的有效期 10年

到这里443 ssl 相关做好了

# vi /etc/nginx/conf/conf.d/odoo.conf  内容如下:

---------------------------------

upstream odoo8 {
        server 127.0.0.1:8069 weight=1 fail_timeout=0;
}

upstream odoo8-im{
        server 127.0.0.1:8072 weight=1 fail_timeout=0;
}

server {
        listen    443 default;
        server_name localhost;

ssl on;
        ssl_certificate  /etc/nginx/ssl/server.crt;
        ssl_certificate_key /etc/nginx/ssl/server.key;

ssl_ciphers               HIGH:!ADH:!MD5;
        ssl_protocols             TLSv1 TLSv1.1 TLSv1.2;
        ssl_prefer_server_ciphers on;

# add ssl specific settings
        keepalive_timeout      60;

# increase proxy buffer to handle some Odoo web requests
        proxy_buffers 16 64k;
        proxy_buffer_size 128k;
       
        underscores_in_headers on;

location / {
                proxy_pass  http://odoo8;

# Force timeouts if the backend dies
                proxy_next_upstream error timeout invalid_header http_500 http_502 http_503 http_504;

# set headers
                proxy_set_header Upgrade $http_upgrade;
                proxy_set_header Connection 'upgrade';
                proxy_set_header Host $host;
                proxy_set_header X-Real-IP $remote_addr;
                proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;

# Let the Odoo web service know that we're using HTTPS, otherwise
                # it will generate URL using http:// and not https://
                proxy_set_header X-Forwarded-Proto https;
                proxy_cache_bypass $http_upgrade;

# By default, do not forward anything
                proxy_buffering off;
                proxy_redirect http:// https://;

proxy_headers_hash_max_size 51200;
                proxy_headers_hash_bucket_size 6400;

# Set timeouts
                proxy_connect_timeout   3600s;
                proxy_send_timeout      3600s;
                proxy_read_timeout      3600s;
                send_timeout            3600s;
        }

location /longpolling/ {

proxy_pass  http://odoo8-im;
                # Force timeouts if the backend dies
                proxy_next_upstream error timeout invalid_header http_500 http_502 http_503 http_504;

# set headers
                proxy_set_header Upgrade $http_upgrade;
                proxy_set_header Connection 'upgrade';
                proxy_set_header Host $host;
                proxy_set_header X-Real-IP $remote_addr;
                proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;

# Let the Odoo web service know that we're using HTTPS, otherwise
                # it will generate URL using http:// and not https://
                proxy_set_header X-Forwarded-Proto https;
                proxy_cache_bypass $http_upgrade;

# By default, do not forward anything
                proxy_buffering off;
                proxy_redirect http:// https://;

proxy_headers_hash_max_size 51200;
                proxy_headers_hash_bucket_size 6400;

# Set timeouts
                proxy_connect_timeout   3600s;
                proxy_send_timeout      3600s;
                proxy_read_timeout      3600s;
                send_timeout            3600s;
        }

location ~* /web/static/ {
                proxy_cache_valid 200 60m;
                proxy_buffering on;
                expires 864000;
                proxy_pass http://odoo8;

}
        access_log  /log/nginx/odoo-ssl.access.log;
        error_log   /log/nginx/odoo-ssl.error.log;

}

server {
        listen    80;
        server_name localhost;

underscores_in_headers on;
        add_header Strict-Transport-Security max-age=2592000;
        rewrite ^/.*$ https://$host$request_uri? permanent;
        error_log   /log/nginx/odoo.error.log;
}
----------------------------------------------

# service nginx start

ok了,可以直接用ip访问,不要再加端口8069 ,有nginx反代理,也解了配置文件 使用workers 这个参数大于1的情况的错误

================配置odoo8与nginx结合 结束===============

(01-02) odoo8.0_Ubuntu14.04_nginx反代理设置的更多相关文章

  1. JMeter学习-024-JMeter 命令行(非GUI)模式详解(二)-执行代理设置

    闲话少述,接 上文 继续... 5.设置代理 jmeter -n -t JMeter分布式测试示例.jmx -H 20.9.215.90 -P 9999 -l report\01-result.csv ...

  2. (34)odoo反代理中客户IP处理

    * 前言    一般我们部署时会用nginx做为前端处理,有时负载时还会用到其它web服务反代理    这里只给出nginx处理方法,其它参考处理    * nginx上的客户IP传递        ...

  3. 【转】使用程序修改系统(IE)代理设置

    文章都是发布在github再转到这边的,这边格式可能会乱掉.博客地址:benqy.com 这是本人在做的一个前端开发调试工具(HttpMock),功能是web服务器+http日记+http代理(类似f ...

  4. 9-python 的ProxyHandler处理器(代理设置)

    ProxyHandler处理器(代理设置) 使用代理IP,这是爬虫/反爬虫的第二大招,通常也是最好用的. 很多网站会检测某一段时间某个IP的访问次数(通过流量统计,系统日志等),如果访问次数多的不像正 ...

  5. ProxyHandler处理器__代理设置__自定义opener

    ProxyHandler处理器(代理设置) 使用代理IP,这是爬虫/反爬虫的第二大招,通常也是最好用的. 很多网站会检测某一段时间某个IP的访问次数(通过流量统计,系统日志等),如果访问次数多的不像正 ...

  6. zabbix被监控端代理设置

    zabbix被监控端代理设置 安装zabbix-agent客户端 rpm -ivh https://repo.zabbix.com/zabbix/4.0/rhel/7/x86_64/zabbix-re ...

  7. 建站第二步:简单配置Nginx反代理工具

    简单配置Nginx反代理工具 你要用你的域名能和服务器绑定就要用一些反代理工具 Nginx (engine x) 是一个高性能的HTTP和反向代理web服务器,极其优异的服务器软件,底层为C 来自某些 ...

  8. android sdk manager 代理设置(送给牛逼的)

    解决android sdk更新慢的问题(公司竟然把sdk更新给墙了). 第一步:如下图 第二部:进入代理设置页面,进行设置.如下图  

  9. sdk更新代理设置

    sdk更新代理设置 http://www.cnblogs.com/zhoujg/p/4560998.html

随机推荐

  1. UITableView heightForHeaderInSection遇到的坑

    出现这种现象只需要把 heightforfoot改为0.01 - (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSectio ...

  2. win10+PHP7

    在D盘自定义新建文件夹ApacheServer 再在ApacheServer文件夹下分别建立php,Apache,mysql,web四个文件夹分别用来存放 php,apache,mysql,项目文件 ...

  3. 【转载】Tomcat崩溃事件

    转载地址:http://www.blogjava.net/tedeyang/archive/2008/06/04/205740.html Tomcat崩溃事件 今天一大早产品一部项目经理就来找我,他们 ...

  4. 初学者-微信小程序 问题解决办法记录

    1.tabBar不显示的问题 1),检查大小写 2),pagePath路径书写,和pages路径一样,不能多或者少一个"/"或者"?" 2.tabBar和nav ...

  5. 在iOS中使用OpenSSL的Public Key 进行加密

    这几天一直潜心于iOS开发,刚好把遇到的问题都记录一下.这次遇到的问题就是如果根据得到的Public Key在iOS 客户端对用户名和密码进行加密. Public Key如下: -----BEGIN ...

  6. [转]VB Winsock 控件TCP与UDP连接实例

    [-] 可能的用途 选择通讯协议 协议的设置 确定计算机的名称 TCP 连接初步 接受多个连接请求 UDP 初步 关于 Bind 方法   利用 WinSock 控件可以与远程计算机建立连接,并通过用 ...

  7. Install Ansible on Mac OSX

    from: https://devopsu.com/guides/ansible-mac-osx.html and : https://devopsu.com/guides/ansible-post- ...

  8. python基础 Day01 练习题

    1 字符串格式化 #!/urs/bin/env python name = input("Name: ") age = int(input("Age: ")) ...

  9. sql 连接查询的区别 inner,left,right,full

    --table1 表 ID NAME QQ PHONE1 秦云 10102800 135000002 在路上 10378 136000003 LEO 10000 139000004 秦云 024145 ...

  10. Lucene 简单API使用

    本demo 简单模拟实现一个图书搜索功能. 模拟向数据库添加数据的时候,添加书籍索引. 提供搜索接口,支持按照书名,作者,内容进行搜索. 按默认规则排序返回搜索结果. Jar依赖: <prope ...