Linux下配置Nginx
环境:
1,Linux服务器 2,nginx-1.10.3.tar.gz http://nginx.org/en/download.html 3,openssl-1.0.2k.tar.gz https://www.openssl.org/ 4,pcre2-10.23.tar.gz http://www.pcre.org/ https://ftp.pcre.org/pub/pcre/ 5,zlib-1.2.11.tar.gz http://www.zlib.net/ 步骤:讲讲我走的岔路吧,一开始看别人写的教程,他只说了安装pcre,我按照他的方法安装完后,去nginx目录下./configura 并不能成功。
后来只能把依赖全部安装上。具体如下:
1,安装openssl
[root@localhost mrms]# tar -zxvf openssl-1.0.2k.tar.gz [root@localhost mrms]# cd openssl-1.0.2k [root@localhost openssl-1.0.2k]# ./config [root@localhost openssl-1.0.2k]# make [root@localhost openssl-1.0.2k]# make install2, 安装zlib
[root@localhost mrms]# tar -zxvf zlib-1.2.11.tar.gz [root@localhost mrms]# cd zlib-1.2.11 [root@localhost zlib-1.2.11]# ./configure [root@localhost zlib-1.2.11]# make [root@localhost zlib-1.2.11]# make install3,安装pcre
[root@localhost mrms]# tar -zxvf pcre-8.40.tar.gz [root@localhost mrms]# cd pcre-8.40 [root@localhost pcre-8.40]# ./configure [root@localhost pcre-8.40]# make [root@localhost pcre-8.40]# make install4,安装nginx
[root@localhost mrms]# tar -zxvf nginx-1.10.3.tar.gz [root@localhost mrms]# cd nginx-1.10.3 [root@localhost nginx-1.10.3]# ./configure --with-pcre=../pcre-8.40 --with-zlib=../zlib-1.2.11 --with-openssl=../openssl-1.0.2k [root@localhost nginx-1.10.3]# make [root@localhost nginx-1.10.3]# make install 检测是否安装成功cd /usr/local/nginx/sbin
./nginx -t
出现下图,说明安装成功。
启动nginx
[root@localhost sbin]# ./nginx查看端口
[root@localhost sbin]# netstat -ntlp修改文件conf/nginx.cnf 配置端口如下:
在浏览器中输入ip:7780
WindowsXP下,配置更简单
我下载的是 nginx-1.10.3.zip,地址是http://nginx.org/en/download.html
解压得到如下文件
修改conf/nginx.cnf文件如下添加集群
#服务器的集群 upstream cast.com { #服务器集群名字 server 192.168.0.65:18080 weight=1;#服务器配置 weight是权重的意思,权重越大,分配的概率越大。 server 192.168.0.65:8888 weight=2; server 192.168.0.7:9090 weight=3; } server { listen 80; server_name localhost; #charset koi8-r; #access_log logs/host.access.log main; #location / { # root html; # index index.html index.htm; #} location / { proxy_pass http://cast.com; proxy_redirect default; }注意集群名的地方要一致。 启动Nginx;start nginx.exe
然后在浏览器中输入地址 http://localhost 就可以了。
完毕!
------------------------------------------------------------分割线--------------------------------------------------------------------------------
有不对的地方还希望指正,谢谢!
下面列份配置
#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; worker_rlimit_nofile 10240; events { worker_connections 10240; } 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; #gzip on; #upstream mysrv { # server 127.0.0.1:9091; # server 127.0.0.1:9092 backup; #热备 #} upstream mysrv { server 127.0.0.1:9091; server 127.0.0.1:9092 backup; #热备 } server { listen 8080; server_name localhost; #charset koi8-r; #access_log logs/host.access.log main; #location / { # root html; # index 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 / { proxy_pass http://mysrv; proxy_redirect default; } # 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; # } #} }
