Linux 下安裝nginx:
http://www.92csz.com/study/linux/17.htm < LNMP安裝>javascript
一. Nginx
===============================================================================================
1.
1)Nginx是一款輕量級的Web 服務器/反向代理服務器及電子郵件代理服務器,並在一個BSD-like 協議下發行。
2)特色: 佔有內存少, 併發能力強 , 事實上nginx的併發能力確實在同類型的網頁服務器中表現較好。
=================== 開始安裝 ==================
1.安裝前環境準備:
#首先確認是否是有安裝編譯包和一些依賴包
# yum install gcc gcc-c++ openssl openssl-devel zib-devel zib
# 建立運行nginx的用戶
# groupadd www
# useradd -M -s /sbin/nologin -g www wwwcss
2.安裝pcre
# wget ftp://ftp.csx.cam.ac.uk/pub/software/programming/pcre/pcre-8.39.tar.gz
#tar zxvf pcre-8.39.tar.gz
編譯安裝
# cd pcre-8.39
# ./configure --prefix=/usr/local/pcre
# make && make install
3.安裝nginx
# wget http://nginx.org/download/nginx-1.6.2.tar.gz
# tar -zxvf nginx-1.6.2.tar.gz
# cd nginx-1.6.2
# ./configure --prefix=/usr/local/nginx --with-pcre --with-http_stub_status_module
# make && make install
4.編輯nginx配置文件
# vi /usr/local/nginx/conf/nginx.conf
=======================如下是配置文件內容===========================
worker_processes 8 #設置跟cpu核數同樣就行
worker_rlimit_nofile 309600;
events {
worker_connections 309600;
use epoll;
}html
http {
include mime.types;
default_type application/octet-stream;
server_tokens off;
gzip on;
gzip_min_length 1k;
gzip_buffers 4 16k;
gzip_http_version 1.0;
gzip_comp_level 4;
gzip_vary on;
gzip_types text/plain text/css text/xml application/x-javascript application/xml application/atom-xml text/javascript;
sendfile on;
keepalive_timeout 15;
client_max_body_size 100m;
client_header_buffer_size 32k;
large_client_header_buffers 4 32k;
client_body_buffer_size 128k;
server {
listen 80; #監聽端口
server_name demo.yunfancdn.com; #主機名
root /webroot/demo.yunfancdn.com; #網站根目錄
client_max_body_size 2M;
index index.html ;
location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)$
{
expires 15d;
}
location ~ .*\.(js|css)?$
{
expires 20m;
}java
}
}linux
5.啓動nginx
檢查nginx配置文件語法有沒問題
#/usr/local/nginx/sbin/nginx -t
若是沒有會出現,下面提示
nginx: the configuration file /usr/local/nginx-1.4.6/conf/nginx.conf syntax is ok
nginx: configuration file /usr/local/nginx-1.4.6/conf/nginx.conf test is successfulnginx
啓動nginx
#/usr/local/nginx/sbin/nginx
從新加載nginx
#/usr/local/nginx/sbin/nginx –s reload
c++
--> 到這一步沒有什麼錯誤,就能夠ip訪問了. web
<======= 注意如下 =======>
* 若是是阿里雲的經典網絡可直接公網ip訪問就能夠了.
* 若是是阿里雲的專有網絡須要在平臺安裝組設置安全規則才能訪問.
* http://blog.csdn.net/assassinsshadow/article/details/72874911 (專有網絡配置介紹)sass
==========================Nginx安裝錯誤總結=======================================
1.nginx安裝 nginx: [emerg] getpwnam(「www」) failed 錯誤?
解決方法1:
在nginx.conf中 把user nobody的註釋去掉既可.安全
===========================================
解決方法2:
錯誤的緣由是沒有建立www這個用戶,應該在服務器系統中添加www用戶組和用戶www,以下命令:
#/usr/sbin/groupadd -f www
#/usr/sbin/useradd -g www www
2.解決nginx: [error] open() "/usr/local/nginx/logs/nginx.pid" failed錯誤
解決方法:
[root@localhost nginx]# /usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf
http://blog.csdn.net/zhouyufengqingyang/article/details/45420775 相關文章
3.http://www.cnblogs.com/cnsanshao/p/3652510.html 解決報錯lib.so
4. ./configure: error: the HTTP rewrite module requires the PCRE library.
安裝pcre-devel解決問題
yum -y install pcre-devel
錯誤提示:./configure: error: the HTTP cache module requires md5 functions
from OpenSSL library. You can either disable the module by using
--without-http-cache option, or install the OpenSSL library into the system,
or build the OpenSSL library statically from the source with nginx by using
--with-http_ssl_module --with-openssl=<path> options.
解決辦法:
yum -y install pcre-devel openssl openssl-devel
./configure --prefix=/usr/local/nginx
make
make install
============= 配置重寫 =================== http://blog.csdn.net/zqtsx/article/details/24729485 配置Url重寫