重启命令:
nginx -s stop && start nginx
nginx -s reload
关闭:
nginx -s stop
启动:
start nginx
window下无法关闭或重启nginx时候可以使用taskkill强制关闭:
taskkill /IM nginx.exe /F
反向代理到百度:
worker_processes 1; events { worker_connections 1024; } http { include mime.types; default_type application/octet-stream; keepalive_timeout 65; server { listen 9000;#监听的端口 server_name localhost; #访问方式:http://127.0.0.1:9000
# 需要注意 proxy_pass http://www.baidu.com 会被百度重定向到https 导致反向代理看上去失败了
# 任何代理如果浏览器端返回重定向 302,304。。都会让反向代理看上去失败了!!!!! location / { proxy_pass https://www.baidu.com:80; }
#反向代理php接口到:8888端口
location ~ /php {
proxy_pass http://localhost:8888;
}
error_page 500 502 503 504 /50x.html;
# error_page 405 =200 $uri; # post 405 无法访问解决方案 location = /50x.html { root html; } } }
location /php { proxy_pass https://fanyi.baidu.com; proxy_set_header Sec-Fetch-Site none;#设置请求头 Sec-Fetch-Site: none proxy_set_header Referer ""; #去除请求头 Referer rewrite '/php(.*)$' '$1' break; #去除访问时候携带的/php路径 }
正向代理FQ:(懂得都懂)
server {
# 配置DNS解析IP地址,比如 Google Public DNS,以及超时时间(5秒)
resolver 8.8.8.8; # 必需
resolver_timeout 5s;
# 监听端口
listen 8080;
access_log /home/reistlin/logs/proxy.access.log;
error_log /home/reistlin/logs/proxy.error.log;
location / {
# 配置正向代理参数
proxy_pass http://$http_host$uri$is_args$args;
# 解决如果URL中带"."后Nginx 503错误
proxy_set_header Host $http_host;
# 配置缓存大小
proxy_buffers 256 4k;
# 关闭磁盘缓存读写减少I/O
proxy_max_temp_file_size 0;
# 代理连接超时时间
proxy_connect_timeout 30;
# 配置代理服务器HTTP状态缓存时间
proxy_cache_valid 200 302 10m;
proxy_cache_valid 301 1h;
proxy_cache_valid any 1m;
}
}
正向代理访问方式:
打开手机或电脑的代理,代理ip为nginx电脑的ip,然后在浏览器输入想访问的网址即可
posted on
浙公网安备 33010602011771号