这里说一下windows环境安装使用方法。
安装:
官网下载:http://nginx.org/ 这里下载最新的nginx-1.15.5。
解压,看到如下文件目录。
启动:
第一种方式:双击nginx.exe,直接启动。(不建议)
第二种方式:进入cmd,并指定配置文件启动。
- cd nginx-1.15.5
- nginx.exe -c conf/nginx2.conf
常用命令:
- nginx -s stop fast shutdown
- nginx -s quit graceful shutdown
- nginx -s reload changing configuration, starting new worker processes with a new configuration, graceful shutdown of old worker processes
- nginx -s reopen re-opening log files
关于启动占用端口:80问题
1.杀死pid=4 进程
- netstat -aon | findstr "80" 查看占用80端口的信息
- taskkill /pid 4 /f其中 /f表示强制关闭该进程
2. 修改nginx.conf文件中监听的端口 listen:81
配置文件:
#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;
upstream server1{ //配置代理多个服务器。
server 127.0.0.1:8097 weight=1;
server 127.0.0.1:8098;
server www.baidu.com weight=5;
}
server {
listen 81; //启动冲突的话注意这里修改端口
server_name localhost;
#charset koi8-r;
#access_log logs/host.access.log main;
location / {
root html;
index index.html index.htm;
proxy_pass http://server1; //配置代理服务器地址
}
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;
# }
#}
}