很多人是使用Nginx作为代理的,比如你安装了PasteSpider之后
一般不会使用加端口的模式进行访问吧,一般会挂载一个域名,比如http://spider.xxx.com/
甚至会给挂载一个https的
这里以https://spider.pastecode.cn为例
如上图所示,我安装后使用的是8006端口
由于外部访问是域名的模式,所以我这里其实8006不需要对外开放这个端口
则我的nginx的配置如下:
server {
server_name spider.pastecode.cn;
#charset koi8-r;
#access_log logs/pastecode.access.log main;
location /api/ {
proxy_pass http://127.0.0.1:8006/api/;
proxy_set_header Host "$server_addr:$server_port";
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header referer "$server_addr:$server_port";
proxy_http_version 1.1;
client_max_body_size 20M;
client_body_buffer_size 20M;
proxy_set_header Connection "Keep-Alive";
proxy_connect_timeout 600;
proxy_send_timeout 600;
proxy_read_timeout 600;
}
location /statushub {
proxy_pass http://127.0.0.1:8006;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $remote_addr;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
}
location /swagger/ {
proxy_pass http://127.0.0.1:8006/swagger/;
proxy_set_header Host "$server_addr:$server_port";
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header referer "$server_addr:$server_port";
proxy_http_version 1.1;
proxy_set_header Connection "Keep-Alive";
proxy_connect_timeout 600;
proxy_send_timeout 600;
proxy_read_timeout 600;
}
location / {
root /spider/static/spider/web;
proxy_set_header Host "$server_addr:$server_port";
index index.html;
}
#location ~/web/(.*)$ {
# root /web/;
# error_page 404 https://www.abc.com/$1;
#}
error_page 404 /404.html;
listen 443 ssl; # managed by Certbot
ssl_certificate /etc/letsencrypt/live/spider.pastecode.cn/fullchain.pem; # managed by Certbot
ssl_certificate_key /etc/letsencrypt/live/spider.pastecode.cn/privkey.pem; # managed by Certbot
include /etc/letsencrypt/options-ssl-nginx.conf; # managed by Certbot
ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem; # managed by Certbot
}
server {
if ($host = spider.pastecode.cn) {
return 301 https://$host$request_uri;
} # managed by Certbot
listen 80;
server_name spider.pastecode.cn pastespider.pastecode.cn;
return 404; # managed by Certbot
}
注意看
location /statushub
由于PasteSpider配置了实时通讯模块,就是管理页面中可以实时被通知
某些任务开始执行
某些任务执行成功
某些任务执行失败等信息
还有一个是
client_max_body_size 20M;
client_body_buffer_size 20M;
由于在升级的时候,如果你使用PasteSpiderFile执行项目文件的同步,则需要考虑这个设置多大,才能使你的项目文件被上传到服务器上!
我上面的配置是PasteSpider的服务端和管理端的代码分开的
看location / { 和 location /api/ { 可以知道
如果是你们使用,一般2个是合并的,如下
server {
server_name spider.pastecode.cn;
#charset koi8-r;
#access_log logs/pastecode.access.log main;
location /statushub {
proxy_pass http://127.0.0.1:8006;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $remote_addr;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
}
location / {
proxy_pass http://127.0.0.1:8006/;
proxy_set_header Host "$server_addr:$server_port";
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header referer "$server_addr:$server_port";
proxy_http_version 1.1;
client_max_body_size 20M;
client_body_buffer_size 20M;
proxy_set_header Connection "Keep-Alive";
proxy_connect_timeout 600;
proxy_send_timeout 600;
proxy_read_timeout 600;
}
#location ~/web/(.*)$ {
# root /web/;
# error_page 404 https://www.abc.com/$1;
#}
error_page 404 /404.html;
listen 443 ssl; # managed by Certbot
ssl_certificate /etc/letsencrypt/live/spider.pastecode.cn/fullchain.pem; # managed by Certbot
ssl_certificate_key /etc/letsencrypt/live/spider.pastecode.cn/privkey.pem; # managed by Certbot
include /etc/letsencrypt/options-ssl-nginx.conf; # managed by Certbot
ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem; # managed by Certbot
}
server {
if ($host = spider.pastecode.cn) {
return 301 https://$host$request_uri;
} # managed by Certbot
listen 80;
server_name spider.pastecode.cn pastespider.pastecode.cn;
return 404; # managed by Certbot
}
在上面中我使用的是let`s encrypt 的证书模式,3个月过期,快到期的时候会自动续期,非常好用!