Linux和WindowXP上安装Nginx,以及简单配置

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 install

2, 安装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 install

3,安装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 install

4,安装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;
    #    }
    #}

}



评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值