开始前先上Frpc.ini跟nginx的配置,可以根据自己的实际情况进行修改优化
[common]
server_addr = 服务器域名或IP
server_port = 7007
token = 密钥
[apilockeyweb1]
type = http
local_ip = 127.0.0.1
local_port = 80
custom_domains = 自己域名
[apilockeyweb2]
type = https
local_ip = 127.0.0.1
local_port = 443
custom_domains = 自己域名
proxy_protocol_version = v2
server {
root /var/www/webapi;
# Add index.php to the list if you are using PHP
index index.php index.html index.htm index.nginx-debian.html;
server_name 域名;
set_real_ip_from 你的frp服务器IP; #你的frp服务器IP
#set_real_ip_from 192.168.1.2; #不用改
set_real_ip_from 127.0.0.1; #不用改
real_ip_header proxy_protocol;
real_ip_recursive off;
location / {
# First attempt to serve request as file, then
# as directory, then fall back to displaying a 404.
#try_files $uri $uri/ =404;
proxy_pass http://localhost:5000;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection keep-alive;
proxy_set_header Host $host;
proxy_cache_bypass $http_upgrade;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
#try_files $uri $uri/ /index.php$is_args$args;
}
#通过创建要求精确匹配的位置开始块/favicon.ico和/robots.txt
#将任何静态文件标记为高度可缓存
location = /favicon.ico { log_not_found off; access_log off; }
location = /robots.txt { log_not_found off; access_log off; allow all; }
location ~* \.(css|gif|ico|jpeg|jpg|js|png)$ {
expires max;
log_not_found off;
}
listen 443 proxy_protocol ssl; # managed by Certbot
ssl_certificate /etc/letsencrypt/live/域名/fullchain.pem; # managed by Certbot
ssl_certificate_key /etc/letsencrypt/live/域名/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 = 域名) {
return 301 https://$host$request_uri;
} # managed by Certbot
listen 80;
server_name 域名;
return 404; # managed by Certbot
}

文章评论