1. 程式人生 > >Ubuntu 18.04.1 nginx 配置安裝

Ubuntu 18.04.1 nginx 配置安裝

  1. 首先需安裝nginx依賴庫
apt-get install build-essential
apt-get install libtool
  1. 安裝pcre依賴庫
sudo apt-get update
sudo apt-get install libpcre3 libpcre3-dev
  1. 安裝zlib依賴庫
apt-get install zlib1g-dev
  1. 安裝ssl依賴庫
apt-get install openssl
  1. nginx download url
  2. tar -zxvf nginx-1.12.2.tar.gz
  3. cd nginx-1.12.2
  4. ./configure --prefix=/usr/local/nginx
nginx path prefix: "/usr/local/nginx"
  nginx binary file: "/usr/local/nginx/sbin/nginx"
  nginx modules path: "/usr/local/nginx/modules"
  nginx configuration prefix: "/usr/local/nginx/conf"
  nginx configuration file: "/usr/local/nginx/conf/nginx.conf"
  nginx pid file: "/usr/local/nginx/logs/nginx.pid"
  nginx error log file: "/usr/local/nginx/logs/error.log"
  nginx http access log file: "/usr/local/nginx/logs/access.log"
  nginx http client request body temporary files: "client_body_temp"
  nginx http proxy temporary files: "proxy_temp"
  nginx http fastcgi temporary files: "fastcgi_temp"
  nginx http uwsgi temporary files: "uwsgi_temp"
  nginx http scgi temporary files: "scgi_temp"

bingo=_=
  1. make
  2. sudo make install
  3. (qidong start)sudo /usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf
  4. (view process) ps -ef|grep nginx
/home/jackray/Public/soft/nginx-1.12.2# ps -ef|grep nginx
root     13803  1178  0 18:59 ?        00:00:00 nginx: master process /usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf
nobody   13804 13803  0 18:59 ?        00:00:00 nginx: worker process
root     13806  1910  0 18:59 pts/0    00:00:00 grep --color=auto nginx
  1. cd /usr/local/nginx/conf/ start to config
  2. touch ihasy.conf
  3. view
/nginx/conf# ls ihasy.conf
ihasy.conf
  1. vim ihasy.conf insert the context like follows
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 ##
                      
  1. shift + : wq! enter ~bingo
  2. /usr/local/nginx/conf# vim nginx.conf
  3. 在http下新增一行
http {
    include ihasy.conf;
  1. pkill -9 nginx

view the ubuntu’s version
how to config nginx for ubuntu