nginx常用配置

修改nginx监听端口,修改http server下的listen节点值,由于本机80端口已经被占用,我改为监听8083端口。
listen 8083;
在http节点下添加upstream(服务器集群),server设置的是集群服务器的信息,我这里搭建了两个站点,配置了两条信息。
#服务器集群名称为Jq_one
upstream Jq_one {
  server 127.0.0.1:9000;
  server 127.0.0.1:8082;
}
在http节点下找到location节点修改
location / {
root html;
index index.aspx index.html index.htm; #修改主页为index.aspx
#其中jq_one 对应着upstream设置的集群名称
proxy_pass http://Jq_one;
#设置主机头和客户端真实地址,以便服务器获取客户端真实IP
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
修改完成配置文件以后记得重启nginx服务,最终完整配置文件信息如下
 
3.运行结果
 
----------------------------后续测试------------------------------
 
 
Microsoft Windows [版本 10.0.14393]
(c) 2016 Microsoft Corporation。保留所有权利。
 
C:\Users\Administrator>cd C:\nginx-1.12.0
 
C:\nginx-1.12.0>nginx -t
nginx: the configuration file C:\nginx-1.12.0/conf/nginx.conf syntax is ok
nginx: configuration file C:\nginx-1.12.0/conf/nginx.conf test is successful
 
C:\nginx-1.12.0>nginx -s reload
 
C:\nginx-1.12.0>start nginx
 
C:\nginx-1.12.0>nginx -s reload
 
C:\nginx-1.12.0>nginx -s reload
 
C:\nginx-1.12.0>nginx -t
nginx: the configuration file C:\nginx-1.12.0/conf/nginx.conf syntax is ok
nginx: configuration file C:\nginx-1.12.0/conf/nginx.conf test is successful
 
C:\nginx-1.12.0>nginx -s reload
 
C:\nginx-1.12.0>start nginx
 
C:\nginx-1.12.0>
 
-----------------config----------------------
 
#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;
 
upstream web_pool {
server 172.21.73.218:81 weight=10; #本机器IIS部署BalanceNode-01
server 172.21.73.105:81 weight=10;
}
 
#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 {
listen 8080;
server_name web_pool;
 
#charset koi8-r;
 
#access_log logs/host.access.log main;
 
location / {
proxy_pass http://web_pool;
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;
# }
#}
 
}
 
 

posted @ 2021-01-26 11:05  小杨ABC  阅读(129)  评论(0编辑  收藏  举报