Nginx配置安装

下载地址

nginx.org/en/download.html

linux版本安装

进入解压后(nginx-source改名)文件的目录
./configure
make
make install
whereis nginx
cd /usr/local/nginx
进入sbin目录中执行
1.启动命令: ./nginx
2.重启命令: ./nginx -s reload
3.关闭命令: ./nginx -s stop

windows版本安装

Nginx 进程项说明
进程1: Nginx主进程 主要负责反向代理的服务. 占用内存大的
进程2: Nginx守护进程 主要负责保护主进程意外关闭的. 占用内存小的
如何手动的关闭: 先关闭守护进程 再关闭主进程
cmd命令
说明: 要求在nignx.exe所在的根目录中执行
启动命令: start nginx 如果nginx配置文件有错 不会打印报错信息
重启命令: nginx -s reload 如果nginx配置文件有错 会打印报错信息
关闭命令: nginx -s stop

nginx配置举例

配置文件在conf/nginx.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
    server {
		#nginx监听的端口号
        listen       80;
		#nginx要拦截的域名
        server_name  localhost;

        #charset koi8-r;

        #access_log  logs/host.access.log  main;
#表示nginx执行反向代理的具体动作
# /代表拦截所有请求
        location / {
			#root代表映射的是一个目录,目录名字为html
            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 ~ \.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;
    #    }
    #}

#以后所有的配置项都要在协议内完成
	server{
		listen 80;
		server_name image.xx.com;
		
		location / {
			root D:/work/s_image;
		}
	}
	#配置后台服务器
	server{
		listen 80;
		server_name manager.xx.com;
		
		location / {
			proxy_pass http://localhost:8080;
			#proxy_pass http://xxWindows;
		}
	}
	#配置tomcat集群,轮询策略,依次访问;weight权重策略(等级);IPHASH(用户绑定,同一个人访问同一台服务器)
	#iphash(hash(ip)%数量)缺点:由于hash计算可能出现负载不均衡
		#如果某台服务器宏机,则直接影响绑定的用户
		#一般hash可以作为压测使用,内部测试
	#down 标识宏机的服务器
	#backup 标识备用机,用户不会访问备用机,当主机遇忙或宏机才会访问
	#max_fails=1 设定最大的失败次数->就规定fail_timeout=60s (60s)不再访问
	upstream xxWindows {
		#ip_hash;
		server localhost:8080 weight=6 backup;
		server localhost:8081 weight=3 down;
		server localhost:8082 weight=1 down;
	}

	#配置前台服务器
	server{
		listen 80;
		server_name www.xx.com;
		
		location / {
			proxy_pass http://localhost:8092;
		}
	}
	server{
		listen 80;
		server_name sso.xx.com;
		
		location / {
			proxy_pass http://localhost:8093;
		}
	}
}
  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

可——叹——落叶飘零

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值