Linux离线安装nginx
先看linux版本,下载相应rpm。
- 安装gcc
- 下载安装包手动安装
- 下载GCC所有需要的依赖包,逐个安装,可以从网站http://www.rpmfind.net/linux/rpm2html/search.php搜索下载,下面是所需要安装的GCC依赖列表
- 安装gcc编译环境依赖(真实版本可能有所不同,这无关紧要):
- 安装gcc模块依赖:cloog-ppl、cpp、glibc-devel、libgomp、libgomp.so.1
- 安装cloog-ppl模块依赖:libppl.so.7、libppl_c.so.2
- 安装libppl.so.7、libppl_c.so.2模块依赖:无
- 安装cpp模块依赖:libmpcfr.so.1
- 安装libmpcfr.so.1模块依赖:无
- 安装glibc-devel模块依赖:glibc-headers
- 安装glibc-headers模块依赖:kernel-headers
- 安装kernel-headers模块依赖:无
- 安装libgomp、libgomp.so.1模块依赖:无
- 安装顺序:
- rpm -ivh ppl-0.10.2-11.el6.x86_64.rpm #ppl(libppl.so.7、libppl_c.so.2)
rpm -ivh cloog-ppl-0.15.7-1.2.el6.x86_64.rpm #cloog-ppl
rpm -ivh mpfr-2.4.1-6.el6.x86_64.rpm #libmpcfr.so.1
rpm -ivh cpp-4.4.7-17.el6.x86_64.rpm #cpp
rpm -ivh kernel-headers-2.6.32-642.el6.x86_64.rpm #kernel-headers
rpm -ivh glibc-headers-2.12-1.192.el6.x86_64.rpm #glibc-headers
rpm -ivh glibc-devel-2.12-1.192.el6.x86_64.rpm #glibc-devel
rpm -ivh libgomp-4.4.7-17.el6.x86_64.rpm #libgomp(libgomp、libgomp.so.1)
rpm -ivh gcc-4.4.7-17.el6.x86_64.rpm #gcc - 至此安装成功
- 安装pcre依赖包:
- rpm -ivh pcre-7.8-7.el6.x86_64.rpm --force(由于机器上已经有低版本的pcre,所以强制安装)。
- rpm -ivh pcre-devel-7.8-7.el6.x86_64.rpm。
- 3.安装libstdc++-devel(gcc-c++依赖)
- rpm -ivh libstdc++-devel-4.4.7-4.el6.x86_64.rpm
- 4.安装gcc-c++
- rpm -ivh gcc-c++-4.4.7-4.el6.x86_64.rpm
- 5.安装zlib-devel
- rpm -ivh zlib-devel-1.2.3-29.el6.x86_64.rpm
- 6.安装nginx
- cd nginx-1.12.1
- ./configure
- make
- make install
- 7.运行nginx
- cd /usr/local/nginx/sbin
- ./nginx
浏览器访问下http:ip 看能否进入nginx首页。
配置nginx : vi /usr/local/nginx/conf/nginx.conf
查看配置是否正确:/usr/local/nginx/sbin/nginx -t
查看nginx进程:ps -ef|grep nginx
强制关闭nginx:pkill nginx
nginx.conf配置文件实例:
==============================================================================================
#user nobody;
worker_processes 2;
#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;
######################主要的######################
upstream site {
#ip_hash (同一ip会被分配给固定的后端服务器,解决session问题)
ip_hash;
server 172.21.132.132:9010;
server 172.21.132.133:9013;
server 172.21.132.134:9014;
server 172.21.132.135:9015;
}
################################################
server {
listen 9019;
server_name site;
charset utf-8;
#access_log logs/host.access.log main;
location / {
root html;
index index.html index.htm;
proxy_pass http://site;
proxy_set_header Host $http_host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
client_max_body_size 100m;
}
#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 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;
# }
#}
}
通过IP访问,可以看到 welcome nginx 的提示
下面我重启linux服务器,重启后通过ip访问,死活连接不上了?没办法了,只有在百度和google
最后发现问题不是出在nginx上,而是出在iptable上,在iptable上添加80端口
- #vi /etc/sysconfig/iptables
- //在倒数第二行加入80端口
- -A RH-Firewall-1-INPUT -m state --state NEW -m tcp -p tcp --dport 80 -j ACCEPT
- //重启iptables
- #/etc/init.d/iptables restart
- 再通过ip访问 ok~ 没问题了