在Linux配置Nginx web伺服器步驟,linuxnginx

來源:互聯網
上載者:User

在Linux配置Nginx web伺服器步驟,linuxnginx

系統內容:centos7

需要軟體:nginx-1.3.16.tar.gz   libevent-2.0.21-stable.tar.gz  Pcre 和 pcre-devel

nginx:http://nginx.org/download/nginx-1.3.16.tar.gz

libevent:http://cloud.github.com/downloads/libevent/libevent/libevent-2.0.21-stable.tar.gz

Project 1:安裝Nginx及配置環境

Step 1:安裝pcre-devel,以及建立nginx使用者

# yum install pcre-devel

# groupadd -r nginx

# useradd -r -g nginx -M nginx

Step 2:解壓縮nginx的源碼並安裝

# tar -zxvf nginx-1.3.16.tar.gz -C /usr/local/src/

# cd /usr/local/src/nginx-1.3.16/

# ./configure \

--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/nginx.pid \

--lock-path=/var/lock/nginx.lock \

--user=nginx \

--group=nginx \

--with-http_ssl_module \

--with-http_flv_module \

--with-http_stub_status_module \

--with-http_gzip_static_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/ \

--with-pcre

# make && make install

# mkdir -p /var/tmp/nginx/client

Step 3:啟動Nginx服務並在用戶端做測試

# /usr/local/nginx/sbin/nginx

在瀏覽器上輸入本機ip

Project 2:實現虛擬機器主機

Step 1:準備工作

# ifconfig eth0:0 192.168.111.20

建立兩個網站目錄

# mkdir /website1

# mkdir /website2

建立兩個存放日誌的目錄

# mkdir /var/log/nginx/website1

# mkdir /var/log/nginx/website2

建立兩個測試頁

# echo "This is website1" >/website1/index.html

# echo "This is website2" >/website2/index.html

Step 2:修改設定檔,原有的設定檔中預設有一個server節點,修改一下,然後再添加一個server節點

server {

listen 192.168.111.10:80;

server_name localhost;

#charset koi8-r;

access_log /var/log/nginx/website1/access.log;

error_log /var/log/nginx/website1/error.log;

location / {

root /website1;

index index.html index.htm;

}

error_page 404 /404.html;

# redirect server error pages to the static page /50x.html

#

error_page 500 502 503 504 /50x.html;

location = /50x.html {

root html;

}

}

server {

listen 192.168.111.20:80;

server_name localhost;

#charset koi8-r;

access_log /var/log/nginx/website2/access.log;

error_log /var/log/nginx/website2/error.log;

location / {

root /website2;

index index.html index.htm;

}

error_page 404 /404.html;

# redirect server error pages to the static page /50x.html

#

error_page 500 502 503 504 /50x.html;

location = /50x.html {

root html;

}

}

此檔案在Nginx安裝目錄下的conf裡面的nginx.conf裡面修改

Step 3:s使用 ./nginx -s reload重新裝在配置

在終端裡面進入到nginx目錄下的sbin,然後使用: ./nginx -s reload 命令進行重新裝載配置

 

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.