Fork me on GitHub

nginx的简单使用

前言:最近使用了两次nginx,第一次正确使用,结果第二次使用没想到查找资料找了一天

nginx:windows版本  

链接:https://pan.baidu.com/s/1H4n1c5B-ow7979czQUgxgQ
提取码:eyk2

 

使用:

第一步:下载该nginx;然后nginx.exe,访问localhost:801,出现十次方界面,则说明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;

 

#转发的ip和端口号
upstream estore_server {
server 127.0.0.1:8085;
server 127.0.0.1:8083;
server 127.0.0.1:8084;
}
server {

#nginx监听的域名和端口号
listen 8281;
server_name ihosp.huaihe.com.cn;

location / {


proxy_pass http://estore_server;
index index.html index.htm;


}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
}

 

 

#转发的ip和端口号
upstream estore_server02 {


server 127.0.0.1:8085;


}

#监听的ip和端口号
server {


listen 8281;
server_name 172.100.99.82;

location / {


proxy_pass http://estore_server02;
index index.html index.htm;


}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}


}


# 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;
# }
#}

}

 

 nginx常用命令

cmd 进入Nginx解压目录 执行以下命令

start nginx : 启动nginx服务

nginx -s reload :修改配置后重新加载生效

nginx -s reopen :重新打开日志文件
nginx -t -c /path/to/nginx.conf 测试nginx配置文件是否正确
---------------------
验证配置是否正确: nginx -t

出现:

 

 则说明配置正确

查看Nginx的版本号:nginx -V

启动Nginx:start nginx

快速停止或关闭Nginx:nginx -s stop

正常停止或关闭Nginx:nginx -s quit

配置文件修改重装载命令:nginx -s reload

nginx的策略模式参考:https://www.cnblogs.com/notyourdog/p/10975283.html

posted @ 2020-09-10 22:05  晨度  阅读(223)  评论(0编辑  收藏  举报