locked
Host ASP.NET Core on Linux with Nginx RRS feed

  • Question

  • User1645444533 posted

    <g class="gr_ gr_13 gr-alert gr_gramm gr_inline_cards gr_run_anim Style multiReplace" id="13" data-gr-id="13">Hi !</g> I'm learning this tutorial https://docs.microsoft.com/en-US/aspnet/core/host-and-deploy/linux-nginx?tabs=aspnetcore2x&view=aspnetcore-2.1

    I need Host ASP.NET Core on my Linux  CentOS with Nginx

    I followed the steps but I have a problem status kestrel-helloapp.service is activating

    ERROR<g class="gr_ gr_15 gr-alert gr_gramm gr_inline_cards gr_run_anim Style replaceWithoutSep" id="15" data-gr-id="15">:"</g>activating"

    [root@CentOS /]# sudo systemctl status kestrel-helloapp.service
    ● kestrel-helloapp.service - Example .NET Core Web App running on CentOS  Loaded: loaded (/etc/systemd/system/kestrel-helloapp.service; enabled; vendor preset: disabled)
       Active: activating (auto-restart) (Result: exit-code) since Sun 2018-11-18 09:45:06 -04; 5s ago
      Process: 16742 ExecStart=/usr/bin/dotnet /usr/share/nginx/html/prueba.dll (code=exited, status=217/USER)
     Main PID: 16742 (code=exited, status=217/USER)

    Status Nginx 

    [root@CentOS ~]# nginx -t
    nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
    nginx: configuration file /etc/nginx/nginx.conf test is successful

    /etc/nginx/nginx.conf

    worker_processes  1;
    events {
        worker_connections  1024;
    }
    
    http {
    
        include       mime.types;
        default_type  application/octet-stream;
        sendfile        on;
        keepalive_timeout  65;
        
        server {
            listen       80;
            server_name  localhost;
    
            #charset koi8-r;
    
            #access_log  logs/host.access.log  main;
    
            location / {
                root   html;
                index  index.html index.htm;
            }
    
            #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;
            }
        }
    }
    

    /etc/nginx/conf.d/default.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;
    
        sendfile        on;
        keepalive_timeout  65;
    
        server {
        listen 80;
        location / {
        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;
        }
    }
    

    my app default root

    /usr/share/nginx/html

    here stay my AppNetCore.dll


    /etc/nginx/proxy.conf 

    proxy_redirect off;
    proxy_set_header Host $host;
    proxy_set_header X-Real-IP $remote_addr;
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    proxy_set_header X-Forwarded-Proto $scheme;
    client_max_body_size 10m; 
    client_body_buffer_size 128k;
    proxy_connect_timeout 90;
    proxy_send_timeout 90;
    proxy_read_timeout 90;
    proxy_buffers 32 4k;
    

    /etc/systemd/system/kestrel-helloapp.service

    [Unit]
    Description=Example .NET Core Web App running on CentOS
    
    [Service]
    WorkingDirectory=/usr/share/nginx/html
    ExecStart=/usr/bin/dotnet /usr/share/nginx/html/prueba.dll
    Restart=always
    # Restart service after 10 seconds if the dotnet service crashes:
    RestartSec=10
    KillSignal=SIGINT
    SyslogIdentifier=dotnet-example
    User=www-data
    Environment=ASPNETCORE_ENVIRONMENT=Production
    Environment=DOTNET_PRINT_TELEMETRY_MESSAGE=false
    
    [Install]
    WantedBy=multi-user.target
    

    Sunday, November 18, 2018 2:40 PM

Answers

  • User1163516801 posted

    The root cause of the issue: 

     (code=exited, status=217/USER)

    is mainly in /etc/systemd/system/kestrel-helloapp.service. Please try to modify the sentence 

    User=www-data

    to

    User=root

    then restart the service with: sudo systemctl daemon-reload

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Wednesday, November 21, 2018 4:09 AM

All replies

  • User1163516801 posted

    The root cause of the issue: 

     (code=exited, status=217/USER)

    is mainly in /etc/systemd/system/kestrel-helloapp.service. Please try to modify the sentence 

    User=www-data

    to

    User=root

    then restart the service with: sudo systemctl daemon-reload

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Wednesday, November 21, 2018 4:09 AM
  • User1645444533 posted
    [root@CentOS ~]# systemctl status kestrel-helloapp.service
    ● kestrel-helloapp.service -Example.NET Web API App running on Ubuntu
       Loaded: loaded (/etc/systemd/system/kestrel-helloapp.se
    rvice; enabled; vendor preset: disabled)
       Active: active (running) since Wed 2018-11-21 10:24:39
    -04; 16min ago
     Main PID: 21366 (dotnet)
       CGroup: /system.slice/kestrel-helloapp.service
               └─21366 /usr/bin/dotnet /usr/share/nginx/html/p
    rueba.dll
    
    Nov 21 10:24:39 CentOS systemd[1]: Started Example .NET We
    b API App running on Ubuntu.
    Nov 21 10:24:39 CentOS systemd[1]: Starting Example .NET W
    eb API App running on Ubuntu...
    Nov 21 10:24:40 CentOS dotnet-example[21366]: Hosting envi
    ronment: Production
    Nov 21 10:24:40 CentOS dotnet-example[21366]: Content root
     path: /usr/share/nginx/html
    Nov 21 10:24:40 CentOS dotnet-example[21366]: Now listenin
    g on: http://localhost:5000
    Nov 21 10:24:40 CentOS dotnet-example[21366]: Now listening on: https://localhost:5001
    Nov 21 10:24:40 CentOS dotnet-example[21366]: Applicationstarted. Press Ctrl+C to shut down.

    <g class="gr_ gr_10 gr-alert gr_spell gr_inline_cards gr_run_anim ContextualSpelling multiReplace" id="10" data-gr-id="10">Thanks</g> You! <g class="gr_ gr_9 gr-alert gr_gramm gr_inline_cards gr_run_anim Punctuation only-ins replaceWithoutSep" id="9" data-gr-id="9">F</g><g class="gr_ gr_9 gr-alert gr_gramm gr_inline_cards gr_disable_anim_appear Punctuation only-ins replaceWithoutSep" id="9" data-gr-id="9">inally</g> the service is active;  I am learning to use Nginx

    Why don't run My <g class="gr_ gr_8 gr-alert gr_spell gr_inline_cards gr_run_anim ContextualSpelling ins-del multiReplace" id="8" data-gr-id="8">webApp</g>?

    error:


    Wednesday, November 21, 2018 2:40 PM
  • User1163516801 posted

    As I cannot reproduce your issue, the 403 http code might be responsed by the Asp.Net Core application. Please double check whether there are any Authentication control in your app.

    Additionally, you can add following sentence in /etc/nginx/nginx.conf to log the nginx service error message:

    error_log  /var/log/nginx/error.log warn;

    with which, you can check the detailed information when the service issue occurs again. 

    Thursday, November 22, 2018 1:50 AM
  • User1645444533 posted

    error_log  /var/log/nginx/error.log warn;

    with which, you can check the detailed information when the service issue occurs again. 

    Not wise on this directory, Thank You!

    2018/11/21 10:24:55 [error] 22514#0: *37 directory index of "/usr/share/nginx/html/" is forbidden, client: 192.168.0.10, server: localhost, request: "GET / HTTP/1.1", host: "192.168.0.2"
    2018/11/21 10:24:56 [error] 22514#0: *37 open() "/usr/share/nginx/html/favicon.ico" failed (2: No such file or directory), client: 192.168.0.10, server: localhost, request: "GET /favicon.ico HTTP/1.1", host: "192.168.0.2", referrer: "http://192.168.0.2/"
    2018/11/21 10:24:59 [error] 22514#0: *37 directory index of "/usr/share/nginx/html/" is forbidden, client: 192.168.0.10, server: localhost, request: "GET / HTTP/1.1", host: "192.168.0.2"
    2018/11/21 10:25:00 [error] 22514#0: *37 directory index of "/usr/share/nginx/html/" is forbidden, client: 192.168.0.10, server: localhost, request: "GET / HTTP/1.1", host: "192.168.0.2"
    2018/11/21 10:26:03 [error] 22514#0: *37 directory index of "/usr/share/nginx/html/" is forbidden, client: 192.168.0.10, server: localhost, request: "GET / HTTP/1.1", host: "192.168.0.2"
    2018/11/21 10:26:09 [error] 22514#0: *37 directory index of "/usr/share/nginx/html/" is forbidden, client: 192.168.0.10, server: localhost, request: "GET / HTTP/1.1", host: "192.168.0.2"
    2018/11/21 10:26:10 [error] 22514#0: *37 directory index of "/usr/share/nginx/html/" is forbidden, client: 192.168.0.10, server: localhost, request: "GET / HTTP/1.1", host: "192.168.0.2"
    2018/11/21 10:26:11 [error] 22514#0: *37 directory index of "/usr/share/nginx/html/" is forbidden, client: 192.168.0.10, server: localhost, request: "GET / HTTP/1.1", host: "192.168.0.2"
    2018/11/21 10:26:11 [error] 22514#0: *37 directory index of "/usr/share/nginx/html/" is forbidden, client: 192.168.0.10, server: localhost, request: "GET / HTTP/1.1", host: "192.168.0.2"
    2018/11/21 10:26:12 [error] 22514#0: *37 directory index of "/usr/share/nginx/html/" is forbidden, client: 192.168.0.10, server: localhost, request: "GET / HTTP/1.1", host: "192.168.0.2"
    2018/11/21 10:26:12 [error] 22514#0: *37 directory index of "/usr/share/nginx/html/" is forbidden, client: 192.168.0.10, server: localhost, request: "GET / HTTP/1.1", host: "192.168.0.2"
    2018/11/21 10:34:29 [error] 22514#0: *41 directory index of "/usr/share/nginx/html/" is forbidden, client: 192.168.0.10, server: localhost, request: "GET / HTTP/1.1", host: "192.168.0.2"
    2018/11/21 11:05:47 [error] 22514#0: *43 directory index of "/usr/share/nginx/html/" is forbidden, client: 192.168.0.10, server: localhost, request: "GET / HTTP/1.1", host: "192.168.0.2"
    2018/11/21 14:22:19 [error] 22514#0: *44 directory index of "/usr/share/nginx/html/" is forbidden, client: 192.168.0.10, server: localhost, request: "GET / HTTP/1.1", host: "192.168.0.2"
    



    Thursday, November 22, 2018 3:49 AM
  • User1163516801 posted

    Directly to this issue: 

    directory index of "/usr/share/nginx/html/" is forbidden

    you can try to change the permission of the folder to `755` or `777`.

    Thursday, November 22, 2018 5:33 AM