安装说明php
系统环境:CentOS-6.3html
软件:nginx-1.9.3.tar.gznginx
安装方式:源码编译安装 c++
安装位置:/usr/local/nginx apache
下载地址:http://nginx.org/en/download.htmlubuntu
安装依赖浏览器
yum install gcc-c++服务器
yum -y install zlib zlib-devel openssl openssl--devel pcre pcre-devel session
下载nginx-1.9.3.tar.gzapp
安装
find -name nginx
yum remove nginx
cd /usr/local/src
tar -zxvf nginx-1.9.3.tar.gz -C ..
cd /usr/local/nginx-1.9.3
./configure --prefix=/usr/local/nginx
make
make install
配置防火墙
vi /etc/sysconfig/iptables
#添加配置
-A INPUT -m state --state NEW -m tcp -p tcp --dport 80 -j ACCEPT
重启防火墙
service iptables restart
启动与测试
/usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf
若是安装了httpd会占用80端口,能够中止apache,经过命令:service httpd stop
中止
#查询nginx主进程号
ps -ef | grep nginx
#中止进程
kill -QUIT 主进程号
#快速中止
kill -TERM 主进程号
#强制中止
pkill -9 nginx
重启
/usr/local/nginx/sbin/nginx -s reload
#测试端口
netstat –na|grep 80
#浏览器中测试
http://ip:80
nginx配置
conf/proxy.conf
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; client_max_body_size 10m; client_body_buffer_size 128k; proxy_connect_timeout 300; proxy_send_timeout 300; proxy_read_timeout 300; proxy_buffer_size 4k; proxy_buffers 4 32k; proxy_busy_buffers_size 64k; proxy_temp_file_write_size 64k;
conf/nginx.conf
user root root; # Nginx所在的用户和用户组 worker_processes 3; # 启动的工做进程数量 #error_log logs/error.log; #error_log logs/error.log notice; #error_log logs/error.log info; pid logs/nginx.pid; # Nginx进程ID 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; upstream localhost { # 发到localhost上的请求,经过Nginx转发到实际处理请求的服务器 server 192.168.0.181:8080 weight=1; server 192.168.0.184:8080 weight=1; } server { listen 8888; # Nginx监听的端口,默认为80 server_name localhost; # Nginx所在主机的名称 #charset koi8-r; #access_log logs/host.access.log main; location / { root html/solr; # 请求资源的路径(代理:/home/shirdrn/servers/nginx/tml/solr/,该目录下没有任何数据) index index.html index.htm; proxy_pass http://localhost; # 代理:对发送到localhost上请求进行代理 include proxy.conf; # 引入proxy.conf配置 } #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; # 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; # server_name localhost; # ssl on; # ssl_certificate cert.pem; # ssl_certificate_key cert.key; # ssl_session_timeout 5m; # ssl_protocols SSLv2 SSLv3 TLSv1; # ssl_ciphers HIGH:!aNULL:!MD5; # ssl_prefer_server_ciphers on; # location / { # root html; # index index.html index.htm; # } #} }
启动nginx
# /usr/local/nginx/sbin/nginx
指定配置文件启动
/usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf
能够查看启动进程
root@dev2:~$ ps -ef | grep nginx root 15952 1 0 18:56 ? 00:00:00 nginx: master process sbin/nginx root 15953 15952 0 18:56 ? 00:00:00 nginx: worker process root 15954 15952 0 18:56 ? 00:00:00 nginx: worker process root 15955 15952 0 18:56 ? 00:00:00 nginx: worker process ubuntu 22988 22887 0 22:19 pts/0 00:00:00 grep --color=auto nginx
查看Nginx监听的端口号
root@dev2:/home/ubuntu# netstat -nap | grep '8888' tcp 0 0 0.0.0.0:8888 0.0.0.0:* LISTEN 15952/nginx