0
我創建了一個ASP.NET Core MVC
應用程序並將其部署到Linux服務器中。當我去sitename.com瀏覽器顯示Home/Index頁面時沒有任何問題。使用nginx路由的Linux上的asp.net核心不起作用
但是當我嘗試去sitename.com/Home/Index
或另一個控制器如sitename.com/Admin/Login
nginx拋出一個404 Not Found
錯誤。應該是什麼問題?我的Startup.cs/Configure
方法。
public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory)
{
loggerFactory.AddConsole(Configuration.GetSection("Logging"));
loggerFactory.AddDebug();
if (env.IsDevelopment())
{
app.UseDeveloperExceptionPage();
app.UseBrowserLink();
}
else
{
app.UseExceptionHandler("/Home/Error");
}
app.UseStaticFiles();
app.UseSession();
app.UseMvc(routes =>
{
routes.MapRoute(
name: "default",
template: "{controller=Home}/{action=Index}/{id?}");
});
}
這裏是sites-available
文件夾我的網站配置
server {
listen 80 default_server;
listen [::]:80 default_server ipv6only=on;
root /var/www/sitename.com;
index index.html index.htm;
server_name sitename.com www.sitename.com;
location/{
try_files $uri $uri/ =404;
proxy_pass http://127.0.0.1:5000;
}
和nginx.conf
user www-data;
worker_processes 4;
pid /run/nginx.pid;
events {
worker_connections 768;
}
http {
sendfile on;
tcp_nopush on;
tcp_nodelay on;
keepalive_timeout 65;
types_hash_max_size 2048;
include /etc/nginx/mime.types;
default_type application/octet-stream;
access_log /var/log/nginx/access.log;
error_log /var/log/nginx/error.log;
gzip on;
gzip_disable "msie6";
include /etc/nginx/conf.d/*.conf;
include /etc/nginx/sites-enabled/*;
}
mail {
}
如果您直接將它們發送到Kestrel,請求是否有效? –
當我在bash上運行這些行時,我會得到正確的html響應。 'curl http:// localhost:5000/Home/Index'或'curl http:// localhost:5000/Admin/Login' @AlexeyAndrushkevich –
然後它值得分享你的'nginx.conf'文件來查看它是否配置正確。 –