centos \u67e5\u770b\u7528\u6237\u7ec4<\/strong>\uff0c\u6211\u4eec\u8fd8\u662f\u91cd\u6e29\u4e00\u4e0b\u5e03\u7f72\u539f\u7406\uff0c\u6b63\u5982\u4f60\u6240\u5e38\u89c1\u7684.NetCore\u5e03\u7f72\u56fe\uff1a<\/p>\n<\/p>\n
\u5728Linux\u4e0a\u5e03\u7f72.NetCoreApp\u6700\u597d\u7684\u65b9\u6cd5\u662f\u4f7f\u7528Kestrel\u670d\u52a1\u5728\u7aef\u53e35000\u4e0a\u652f\u6491web\u5e94\u7528\uff1b\u4e4b\u540e\u8bbe\u7f6eNginx\u4f5c\u4e3a\u53cd\u5411\u4ee3\u7406\u670d\u52a1\u5668\uff0c\u5c06\u8f93\u5165\u6073\u6c42\u8f6c\u53d1\u7ed9Kestrel\u670d\u52a1\u5668\uff0c\u8fd9\u4e2a\u6a21\u5f0f\u79f0\u4e3a\u8fb9\u6cbf\u4ee3\u7406\u670d\u52a1\u5668\uff08edge-originproxy\uff09\u3002<\/p>\n
\u5e03\u7f72\u6a21\u578b\u4f18\u52bf\uff1a<\/p>\n
\u77e5\u8bc6\u6253\u7b97<\/p>\n
\u9996\u5148\u660e\u6670dotnet\u7a0b\u5e8f\u662f\u4e00\u4e2a\u72ec\u7acb\u8fdb\u7a0b\uff0c\u672c\u6765\u53ef\u4e0d\u4f9d\u8d56\u53cd\u5411\u4ee3\u7406\u670d\u52a1\u5668\u8fd0\u884c\uff1b<\/p>\n
<\/p>\n
\u7b2c\u4e8c\u660e\u6670Nginx\u53cd\u5411\u4ee3\u7406\u670d\u52a1\u5668\u7684\u4f5c\u7528,\u8fd9\u513f\u987b\u8981\u4e3a.NetCore\u7a0b\u5e8f\u6dfb\u52a0\u5fc5\u8981\u7684\u8f6c\u53d1\u4e2d\u95f4\u4ef6<\/p>\n
\n
\/\/ Invoke the UseForwardedHeaders middleware and configure it to forward the X-Forwarded-For and X-Forwarded-Proto headers.
\/\/ NOTE: This must be put BEFORE calling UseAuthentication or similar authentication scheme middlewares.
\/\/ ref.: https:\/\/www.ryadel.com\/en\/asp-net-core-2-publish-deploy-web-application-linux-centos-tutorial-guide-nginx
app.UseForwardedHeaders(new ForwardedHeadersOptions
{
ForwardedHeaders = ForwardedHeaders.XForwardedFor | ForwardedHeaders.XForwardedProto
});
<\/code><\/pre>\n<\/p>\n\u7b2c\u4e09\u660e\u6670dotnet\u7a0b\u5e8f\u987b\u8981\u5728Linux\u7cfb\u7edf\u4e2d\u4ee5\u5b88\u62a4\u8fdb\u7a0b\u7684\u5f62\u5f0f\u8fd0\u884c\uff0c\u53ef\u4f7f\u7528supervisor\u3001systemd\u7b49\u7ba1\u63a7\u5de5\u5177\u3002<\/p>\n
CentOS\u5e03\u7f721.\u5b89\u88c5\u73af\u5883<\/p>\n
\n
sudo rpm -Uvh https:\/\/packages.microsoft.com\/config\/rhel\/7\/packages-microsoft-prod.rpm
-- rpm\u662f\u4e00\u79cd\u8f6f\u4ef6\u5305\u7ba1\u7406\u65b9\u5f0f\uff0c\u8fd9\u91cc\u7684\u5fae\u8f6f\u8f6f\u4ef6\u5305\u4ed3\u5e93\u4ee5rpm\u5305\u7684\u5f62\u5f0f\u63d0\u4f9b\uff0c\u5305\u542b\u4ed3\u5e93\u914d\u7f6e\u548c\u4f9b\u53d1\u884c\u7248\u8ba4\u8bc1\u8f6f\u4ef6\u5305\u7684\u516c\u94a5\uff0c\u4f60\u53ef\u4ee5\u7406\u89e3\u4e3a\u6dfb\u52a0\u4e86\u4e00\u4e2anuget\u5305\u4ed3\u5e93
sudo yum update
sudo yum install aspnetcore-runtime-2.2 \u3000\u3000\u3000\u3000\u3000\u3000\u3000\u3000\u3000\u3000\u3000\u3000\u3000\u3000\u3000\u3000\u3000\u3000\u3000\u3000\u3000\u3000\u3000\u3000\u3000\u3000\u3000\u3000
-- yum\u57fa\u4e8erpm\u5305\u7ba1\u7406\uff0c\u80fd\u591f\u4ece\u6307\u5b9a\u670d\u52a1\u5668\u81ea\u52a8\u4e0b\u8f7drpm\u5305\u5e76\u4e14\u5b89\u88c5\uff0c\u53ef\u81ea\u52a8\u5904\u7406\u4f9d\u8d56\u5173\u7cfb\uff0c\u5e76\u4e00\u6b21\u5b89\u88c5\u6240\u6709\u4f9d\u8d56\u8f6f\u4ef6\u5305\u3002
<\/code><\/pre>\n<\/p>\n2.dotnet\u7a0b\u5e8f\u53d1\u5e03\u3001\u6d4b\u8bd5<\/p>\n
\n
scp D:productioneqidproxyServer.zip root@10.201.80.126:\/var\/www --\u4ee5\u4e0b\u547d\u4ee4\u5c06zip\u5305\u62f7\u8d1d\u5230 \/var\/www\u76ee\u5f55\u4e0b
<\/code><\/pre>\n<\/p>\n<\/p>\n
\n
unzip -d eqidproxyServer eqidproxyServer.zip
<\/code><\/pre>\n<\/p>\n3.\u4f7f\u7528systemd\u5c06dotnet\u8fdb\u7a0b\u8bbe\u7f6e\u6210Linux\u5b88\u62a4\u8fdb\u7a0b<\/p>\n
\u5b8c\u6210\u4ee5\u4e0a\u6b65\u9aa4centos \u67e5\u770b\u7528\u6237\u7ec4<\/strong>\uff0cdotnet\u7a0b\u5e8f\u5e76\u4e0d\u80fd\u5728\u540e\u53f0\u4f5c\u4e3a\u670d\u52a1\u8fd0\u884clinux\u91cd\u542f\u547d\u4ee4\uff0cNginx\u4f3c\u4e4e\u80fd\u4f5c\u4e3a\u53cd\u5411\u4ee3\u7406\u670d\u52a1\u5668\u8f6c\u53d1\u6073\u6c42\u5230dotnet\u8fdb\u7a0b\uff0c\u800c\u4e14\u5e76\u4e0d\u5177\u5907\u7ba1\u7406dotnet\u8fdb\u7a0b\u7684\u80fd\u529b\u3002<\/p>\n\u4e0b\u8fb9\u4f7f\u7528systemd\u6765\u5c06dotnet\u8fdb\u7a0b\u8bbe\u5b9a\u4e3a\u7cfb\u7edf\u670d\u52a1\u3002<\/p>\n
systemd\u662f\u4e00\u4e2aLinux\u7684\u7cfb\u7edf\u670d\u52a1\u7ba1\u7406\u5668\uff0c\u5176\u4f5c\u7528\u662f\u63d0\u4f9b\u7cfb\u7edf\u670d\u52a1\u4f9d\u8d56\u7ba1\u7406\u3001\u5b9e\u73b0\u7cfb\u7edf\u521d\u59cb\u5316\u65f6\u670d\u52a1\u7684\u5e76\u884c\u542f\u52a8\u3002<\/p>\n
\u2460\u521b\u5efa\u670d\u52a1\u6587\u4ef6\uff1avim\/etc\/systemd\/system\/kestrel-eqidproxyserver.service<\/p>\n
\n
[Unit]
Description=EqidProxyServer deploy on centos
[Service]
WorkingDirectory=\/var\/www\/eqidproxyserver\/eqidproxyServer
ExecStart=\/usr\/bin\/dotnet \/var\/www\/eqidproxyserver\/eqidproxyServer\/EqidProxyServer.dll<\/span>
Restart=always
# Restart service after 10 seconds if the dotnet service crashes:
RestartSec=10
TimeoutStopSec=90
KillSignal=SIGINT
SyslogIdentifier=dotnet-example
User=root<\/span>
Environment=ASPNETCORE_ENVIRONMENT=Production
Environment=DOTNET_PRINT_TELEMETRY_MESSAGE=false
[Install]
WantedBy=multi-user.target
<\/code><\/pre>\n<\/p>\n<\/p>\n
\u7eff\u8272\u80cc\u666f\u884c\u662f\u987b\u8981\u4f60\u6ce8\u610f\u914d\u7f6e\u7684\uff0c\u8fd9\u513f\u6211\u4eec\u4f7f\u7528root\u6765\u6267\u884cdll\uff0c\u901a\u5e38\u60c5\u51b5\u4e0b\u987b\u8981\u521b\u5efa\u4e00\u4e2aweb\u5e10\u6237\uff0c\u5e76\u7ed9\u4e0e\u9879\u76ee\u6587\u4ef6\u5939owner\u6743\u9650\u3002<\/p>\n
\u4e0b\u8fb9\u5728root\u7528\u6237\u7ec4\u4e0b\u521b\u5efawww-data\u7528\u6237\uff0c\u5e76\u7ed9\u4e0eowner\u6743\u9650<\/p>\n
\n
sudo useradd -m -g root www-data
sudo chown www-data var\/www\/eqidproxyserver
<\/code><\/pre>\n<\/p>\n\u6ce8\u610f\uff1aLinux\u662f\u5927\u5c0f\u5199\u654f\u611f\u7684\u6587\u4ef6\u7cfb\u7edf\uff0c\u8bbe\u5b9aASPNETCORE_ENVIRONMENT=Production\u4f1a\u5728\u914d\u7f6e\u6587\u4ef6\u4e2d\u641c\u7d22\u5982\u4e0b\u914d\u7f6e\u6587\u4ef6\uff1aappsettings.Production.json\uff0c\u6545\u914d\u7f6e\u548c\u6587\u4ef6\u540d\u987b\u8981\u7559\u5fc3\u5339\u914d\u3002<\/p>\n
\u2461\u542f\u7528\u3001\u542f\u52a8\u670d\u52a1<\/p>\n
\n
sudo systemctl enable kestrel-eqidproxyserver.service \u3000\u3000\u3000\u3000\u3000\u3000\/\/ \u542f\u7528\u670d\u52a1<\/span>
sudo systemctl start kestrel-eqidproxyserver.service \u3000\u3000\u3000\u3000\u3000\u3000 \/\/ \u6307\u5b9a\u670d\u52a1\u540d\u542f\u52a8<\/span>
sudo systemctl status kestrel-eqidproxyserver.service \u3000\u3000\u3000\u3000\u3000\u3000\/\/ \u9a8c\u8bc1\u670d\u52a1\u72b6\u6001<\/span>
<\/code><\/pre>\n<\/p>\n\u4ee5\u4e0b\u662f\u9a8c\u8bc1\u670d\u52a1\u72b6\u6001\u7684\u8f93\u51fa\uff1a<\/p>\n
<\/p>\n
\n
\u25cf kestrel-eqidproxyserver.service - EqidProxyServer deploy on centos
Loaded: loaded (\/etc\/systemd\/system\/kestrel-eqidproxyserver.service; enabled; vendor preset: disabled)
Active: active (running) since Thu 2019-02-28 18:04:20 CST; 3min 2s ago
Main PID: 52859 (dotnet)
Memory: 46.3M
CGroup: \/system.slice\/kestrel-eqidproxyserver.service
\u2514\u250052859 \/usr\/bin\/dotnet \/var\/www\/eqidproxyserver\/eqidproxyServer\/EqidProxyServer.dll
Feb 28 18:06:18 gs-server-5809 dotnet-eqidproxyserver[52859]: info: Microsoft.AspNetCore.Hosting.Internal.WebHost[2]
Feb 28 18:06:18 gs-server-5809 dotnet-eqidproxyserver[52859]: Request finished in 136.6715ms 200
Feb 28 18:06:23 gs-server-5809 dotnet-eqidproxyserver[52859]: info: Microsoft.AspNetCore.Hosting.Internal.WebHost[1]
Feb 28 18:06:23 gs-server-5809 dotnet-eqidproxyserver[52859]: Request starting HTTP\/1.1 GET http:\/\/127.0.0.1\/
Feb 28 18:06:23 gs-server-5809 dotnet-eqidproxyserver[52859]: info: Microsoft.AspNetCore.Hosting.Internal.WebHost[2]
Feb 28 18:06:23 gs-server-5809 dotnet-eqidproxyserver[52859]: Request finished in 3.5599ms 200
Feb 28 18:06:32 gs-server-5809 dotnet-eqidproxyserver[52859]: info: Microsoft.AspNetCore.Hosting.Internal.WebHost[1]
Feb 28 18:06:32 gs-server-5809 dotnet-eqidproxyserver[52859]: Request starting HTTP\/1.1 GET http:\/\/10.201.80.126\/
Feb 28 18:06:32 gs-server-5809 dotnet-eqidproxyserver[52859]: info: Microsoft.AspNetCore.Hosting.Internal.WebHost[2]
Feb 28 18:06:32 gs-server-5809 dotnet-eqidproxyserver[52859]: Request finished in 1.3498ms 200
<\/code><\/pre>\n<\/p>\n4.\u642d\u914dNginx\u5e03\u7f72web\u7a0b\u5e8f<\/p>\n
\u2460\u5b89\u88c5Nginx,\u5728\u7ec8\u7aef\u4f7f\u7528curllocalhost\u6d4b\u8bd5nginx<\/p>\n
\n
sudo yum install nginx\u3000\u3000\u3000\u3000\u3000\u3000\u3010\u9996\u6b21\u5b89\u88c5\u9700\u8981\u663e\u5f0f\u542f\u52a8\uff1asudo service nginx start\u3011
<\/code><\/pre>\n<\/p>\nCentOS\u5b89\u88c5\u7684nginx\u5e76\u6ca1\u6709\u4f5c\u4e3a\u5b88\u62a4\u8fdb\u7a0b\u8fd0\u884c\uff0c\u6267\u884csudosystemctlenablenginx\u542f\u7528nginx\u5b88\u62a4\u8fdb\u7a0b<\/p>\n
\u2461\u914d\u7f6eNginx\u4f5c\u4e3a\u53cd\u5411\u4ee3\u7406\u670d\u52a1\u5668<\/p>\n
\n
server {
listen 80<\/span>;
server_name default_website;
root \/usr\/share\/nginx\/html;
# Load configuration files for the default server block.
include \/etc\/nginx\/default.d\/*.conf;
location \/ {
proxy_pass http:\/\/localhost:5000<\/span>;
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;
proxy_set_header X-Forwarded-Proto $scheme;
}
error_page 404 \/404.html;
location = \/40x.html {
}
error_page 500 502 503 504 \/50x.html;
location = \/50x.html {
}
}
<\/code><\/pre>\n<\/p>\n\u4e00\u65e6nginx\u914d\u7f6e\u5b8c\u6210\uff0c\u53ef\u4ee5\u4f7f\u7528sudonginx-t\u6d4b\u8bd5\u914d\u7f6e\u6587\u4ef6\uff1b<\/p>\n
\u5047\u5982\u914d\u7f6e\u6587\u4ef6\u5408\u6cd5\uff0c\u91cd\u542fnginx(sudonginx-sreload)<\/p>\n
\u5b8c\u6210\u4ee5\u4e0a\u6b65\u9aa4\u8fc7\u540e\uff0c\u5982\u4eca\u5df2\u7136\u53ef\u4ee5\u4ece127.0.0.1\u3001127.0.0.1:5000\u3001\u670d\u52a1\u5668IP\u8bbf\u95eeweb\u7a0b\u5e8f\u3002<\/p>\n
5.\u67e5\u770b\u8fdb\u7a0b\u65e5\u5fd7<\/p>\n
\u4f7f\u7528systemd\u5f62\u5f0f\u7ba1\u7406\u8fdb\u7a0b\uff0c\u6240\u6709\u98ce\u6ce2\u548c\u8fdb\u7a0b\u5c31\u4f1a\u8bb0\u5f55\u5230\u67d0\u4e2a\u96c6\u4e2d\u65e5\u5fd7linux vi\u547d\u4ee4\uff0c\u8be5\u96c6\u4e2d\u65e5\u5fd7\u5305\u542b\u6240\u6709\u88absystend\u7ba1\u7406\u7684\u670d\u52a1\u548c\u8fdb\u7a0b\u7684\u65e5\u5fd7\u3002(\u8fd9\u4e2a\u65e5\u5fd7\u529f\u80fd\u76f8\u5f53\u4e8ewindows\u670d\u52a1\u5668\u4e2d\u7684\u98ce\u6ce2\u67e5\u770b\u5668)<\/p>\n
\u67e5\u770b\u521a\u521a\u5b8c\u5584\u7684\u670d\u52a1\u65e5\u5fd7\uff0c\u53ef\u4f7f\u7528\u4e0b\u8fb9\u7684\u547d\u4ee4<\/a>\uff1a<\/p>\n\n
sudo journalctl -fu kestrel-eqidproxysever.service
\/\/ \u65f6\u95f4\u8fc7\u6ee4\uff1a<\/span>
sudo journalctl -fu kestrel-eqidproxysever.service --since \"2018-11-18\" --until \"2019-03-28 04:00\"
<\/code><\/pre>\n<\/p>\n<\/p>\n","protected":false},"excerpt":{"rendered":"
\u4f7f\u7528systemd\u5c06dotnet\u8fdb\u7a0b\u8bbe\u7f6e\u6210Linux\u5b88\u62a4\u8fdb\u7a0bsystemd\u6765\u5c06dotnet\u8fdb\u7a0b\u8bbe\u5b9a\u4e3a\u7cfb\u7edf\u670d\u52a1\u3002\u3001\u5b9e\u73b0\u7cfb\u7edf\u521d\u59cb\u5316\u65f6\u670d\u52a1\u7684\u5e76\u884c\u542f\u52a8\u3002\u4e0b\u9762\u5728root\u7528\u6237\u7ec4\u4e0b\u521b\u5efawww-data\u7528\u6237\uff0c\u5e76\u7ed9\u4e88owner\u6743\u9650(\u8fd9\u4e2a\u65e5\u5fd7\u529f\u80fd\u76f8\u5f53\u4e8ewindows\u670d\u52a1\u5668\u4e2d\u7684\u4e8b\u4ef6\u67e5\u770b\u5668)<\/p>\n","protected":false},"author":1,"featured_media":293331,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[988],"tags":[3314,3313,3315],"class_list":["post-293330","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-tougao","tag-cbs","tag-zscyy","tag-yzfwzt"],"acf":[],"_links":{"self":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts\/293330","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/comments?post=293330"}],"version-history":[{"count":0,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts\/293330\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/media\/293331"}],"wp:attachment":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/media?parent=293330"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/categories?post=293330"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/tags?post=293330"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}