ubuntu环境
No LSB modules are available.
Distributor ID: Ubuntu
Description: Ubuntu 14.04.5 LTS
Release: 14.04
Codename: trusty
nginx和php安装无所谓先后,这里先安装nginx
nginx
先下载所需的依赖
openssl-fips-2.0.13.tar.gz
pcre-8.31.tar.gz
zlib-1.2.8.tar.gz
nginx安装包
解压缩
sudo tar -zxvf openssl-fips-2.0.13.tar.gz -C /usr/local/src/
sudo tar -zxvf pcre-8.31.tar.gz -C /usr/local/src/
sudo tar -zxvf zlib-1.2.8.tar.gz -C /usr/local/src/
sudo tar -zxvf nginx-1.11.3.tar.gz -C /usr/local/src/
安装
cd /usr/local/src
cd openssl-fips-2.0.13/
sudo ./config
sudo make
sudo make install
cd ../pcre-8.31/
sudo ./configure --prefix /usr/local/
sudo make
上一步如果出现 make[1]: * [pcrecpp.lo] Error 1
则需要安装gcc 执行
sudo apt-get install build-essential
安装完成之后,记得先 sudo make clean
再重新来
sudo ./configure --prefix /usr/local/
sudo make
sudo make install
cd ../zlib-1.2.8
sudo ./configure --prefix /usr/local/
sudo make
sudo make install
cd ../nginx-1.11.3/
sudo ./configure --with-pcre=/usr/local/src/pcre-8.31 --with-openssl=/usr/local/src/openssl-fips-2.0.13 --with-zlib=/usr/local/src/zlib-1.2.8
sudo make
sudo make install
测试nginx是否安装成功
cd ../../nginx/sbin/
sudo ./nginx -t
出现如下提示,表示成功。
尝试开启nginx服务,放在init.d中路径好记一点
sudo cp nginx /etc/init.d/
sudo /etc/init.d/nginx -s reload
会出现如下错误 nginx: [error] invalid PID number “” in “/usr/local/nginx/logs/nginx.pid”
执行
sudo /etc/init.d/nginx -c /usr/local/nginx/conf/nginx.conf
再重启,查看是否成功
ps aux |grep nginx
看到类似进程表示成功
root 8422 0.0 0.2 20300 2692 ? Ss 19:13 0:00 nginx: master process /etc/init.d/nginx -c /usr/local/nginx/conf/nginx.conf
nobody 8426 0.0 0.2 20728 2288 ? S 19:13 0:00 nginx: worker process
niezuxue 8428 0.0 0.2 15944 2176 pts/14 S+ 19:15 0:00 grep --color=auto ngin``
另贴出我的ng.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 {
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 80;
server_name localhost;
#charset koi8-r;
access_log logs/host.access.log;
location / {
root /home/niezuxue/Documents/projects;
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 /home/niezuxue/Documents/projects$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 8000;
# listen somename:8080;
# server_name somename alias another.alias;
# location / {
# root html;
# index 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;
# }
#}