记录,备查
nginx反向代理两个服务器
服务器一:
https://www.kwaili.com:9696
提供https服务,http访问会转https访问
外网访问:https://www.kwaili.com
服务器二:
http://127.0.0.1:5000
个人博客,仅内网能够访问
外网访问开了两个口子:
博客文章清单:http://127.0.0.1:5000/wxlist
博客文章正文:http://127.0.0.1:5000/wxpost
同时允许静态资源访问:http://127.0.0.1:5000/static
外网访问:https://www.kwaili.com/wxlist
外网访问:https://www.kwaili.com/wxpost/56
以上两个外网访问用于嵌入小程序中访问
page.wxml
<web-view src="{{path}}"></web-view>
page.js
path: 'https://www.kwaili.com/wxlist'
小程序应用效果
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;
# start nginx
# nginx -s stop
# nginx -s reload
# tasklist /fi "imagename eq nginx.exe"
# taskkill /im nginx.exe /f
server {
listen 80;
server_name kwaili.com;
#charset koi8-r;
#access_log logs/host.access.log main;
location / {
return 301 https://www.kwaili.com;
}
#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;
#}
}
# HTTPS server
server {
listen 443 ssl;
server_name kwaili.com;
ssl_certificate www.kwaili.com_bundle.pem;
ssl_certificate_key www.kwaili.com.key;
ssl_session_cache shared:SSL:1m;
ssl_session_timeout 5m;
ssl_ciphers HIGH:!aNULL:!MD5;
ssl_prefer_server_ciphers on;
location ^~ /wxlist/ {
proxy_pass http://127.0.0.1:5000/wxlist;
proxy_redirect off;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Remote_addr $remote_addr;
}
location ^~ /wxpost/ {
proxy_pass http://127.0.0.1:5000;
proxy_redirect off;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Remote_addr $remote_addr;
}
location ^~ /static/ {
proxy_pass http://127.0.0.1:5000;
proxy_redirect off;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Remote_addr $remote_addr;
}
location / {
proxy_pass https://www.kwaili.com:9696;
}
}
}
Windows下Nginx常用命令
启动
start nginx
停止
nginx -s stop
重启
nginx -s reload
查询nginx进程
tasklist /fi "imagename eq nginx.exe"
杀死nginx进程
taskkill /im nginx.exe /f