您的位置:首页 > 运维架构 > Nginx

安装配置nginx

2016-04-26 17:45 567 查看
yum -y install gcc automake autoconf libtool make

yum -y install gcc gcc-c++

先安装pcre, zlib,前者为了重写rewrite,后者为了gzip压缩。
1.选定源码目录
可以是任何目录,这里选定的是/usr/local/src

cd /usr/local/src

2.安装PCRE库 ftp://ftp.csx.cam.ac.uk/pub/software/programming/pcre/ 下载最新的 PCRE 源码包

tar -zxvf pcre-8.38.tar.gz
cd pcre-8.38
./configure
make
make install

3.安装zlib库
wget http://zlib.net/zlib-1.2.8.tar.gz tar -zxvf zlib-1.2.8.tar.gz
cd zlib-1.2.8
./configure
make
make install

4.安装ssl(如果默认没装ssl)
cd /usr/local/src
wget http://www.openssl.org/source/openssl-1.0.2g.tar.gz

cd openssl-1.0.2g
./config
make
make install

5.安装nginx1.8.1

yum -y install gcc gcc-c++ autoconf automake zlib zlib-devel openssl openssl-devel

groupadd nginx
useradd -g nginx -s /sbin/nologin nginx

tar zxvf nginx-1.8.1.tar.gz
cd nginx-1.8.1

./configure --prefix=/usr/local/nginx --user=nginx --group=nginx --with-http_stub_status_module --with-http_dav_module --with-http_addition_module --with-http_sub_module --with-http_flv_module --with-http_mp4_module --with-pcre=/usr/local/src/pcre-8.38

make
make install

编辑主配置文件nginx.conf

cd /usr/local/nginx/conf

vi nginx.conf

#user nobody;
worker_processes 1;

#error_log logs/error.log;
#error_log logs/error.log notice;
#error_log logs/error.log info;

#pid logs/nginx.pid;

events {
use epoll;
worker_connections 1024;
}

http {
include mime.types;
default_type application/octet-stream;

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

#access_log logs/access.log main;

sendfile on;
#tcp_nopush on;

#keepalive_timeout 0;
keepalive_timeout 65;

#gzip on;

server {
listen 88;
server_name mcs.vcfilm.cn;

#charset koi8-r;

#access_log logs/host.access.log main;

location / {
root /mcs/portal/web;
index index.php 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;
}

# proxy the PHP scripts to Apache listening on 127.0.0.1:80
#
#location ~ \.php$ {
# proxy_pass http://127.0.0.1; #}

# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
#
location ~ \.php$ {
root html;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
#fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}

# deny access to .htaccess files, if Apache's document root
# concurs with nginx's one
#
#location ~ /\.ht {
# deny all;
#}
}

# another virtual host using mix of IP-, name-, and port-based configuration
#
server {
listen 88;
#listen somename:8080;
server_name www.jiashenzhen.com;

location / {
root html;
index index.php index.html index.htm;
}
}

# HTTPS server
#
#server {
# listen 443 ssl;
# server_name localhost;

# ssl_certificate cert.pem;
# ssl_certificate_key cert.key;

# ssl_session_cache shared:SSL:1m;
# ssl_session_timeout 5m;

# ssl_ciphers HIGH:!aNULL:!MD5;
# ssl_prefer_server_ciphers on;

# location / {
# root html;
# index index.html index.htm;
# }
#}

}

主要修改端口 listen 88;
虚拟域名server_name mcs.vcfilm.cn;
网页路径root /mcs/portal/web;
头文件 index index.php index.html index.htm;

添加php端口
location ~ \.php$ {
root html;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
#fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}

改完之后启动nginx

/usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf

看下进程 ps -ef | grep nginx

看下端口 netstat -nltp | grep nginx
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  local