Deploying ASP.NET 4.* MVC and Web API applications to Linux server - asp.net

Is there any way of Deploying ASP.NET 4.* MVC and Web API applications to Linux server? I searched and read about Docker but I think that is for .NET 5.
Appreciate your help!

I managed to do that with some bricolage on a Linux-based Docker image.
This helped me a lot: https://github.com/junalmeida/docker-mono-web
Basically, you can host your web application with nginx, but you also need fastcgi-mono-server4.
The dockerfile looks like this:
FROM mono:latest
RUN apt-get update \
&& apt-get install -y \
iproute2 supervisor ca-certificates-mono fsharp mono-vbnc nuget \
referenceassemblies-pcl mono-fastcgi-server4 nginx nginx-extras \
&& rm -rf /var/lib/apt/lists/* /tmp/* \
&& echo "daemon off;" | cat - /etc/nginx/nginx.conf > temp && mv temp /etc/nginx/nginx.conf \
&& sed -i -e 's/www-data/root/g' /etc/nginx/nginx.conf
# this copies nginx configuration files to the proper directory
COPY nginx/ /etc/nginx/
In the link above, the supervisord command is used to start both nginx and fastcgi-mono-server4.
It is configured in a supervisord.conf file like the following, in which the --appconfigdir specifies the root folder of your application:
[supervisord]
logfile=/var/log/supervisor/supervisord.log
logfile_maxbytes = 50MB
nodaemon=true
user=root
[program:mono]
command=fastcgi-mono-server4 --appconfigdir=appconfig --socket=unix --filename=/var/run/mono-fastcgi.sock --printlog --name=mono
user=root
stdout_logfile=/dev/stdout
stdout_logfile_maxbytes=0
stderr_logfile=/dev/stderr
stderr_logfile_maxbytes=0
[program:nginx]
command=nginx
user=root
stdout_logfile=/dev/stdout
stdout_logfile_maxbytes=0
stderr_logfile=/dev/stderr
stderr_logfile_maxbytes=0
and launched with this command:
/usr/bin/supervisord -c supervisord.conf
(a folder contains a configuration for nginx, too).

Related

Varnish 6.0.8 Secret file is not created

Please we're facing some issues when installing Varnish 6.0.8 on ubutnu 18.04.6 OS, it doesn't create the secret file inside the /etc/varnish dir as shown below:
enter image description here
we use the following script to for installation :
curl -s https://packagecloud.io/install/repositories/varnishcache/varnish60lts/script.deb.sh | sudo bash
can someone please help ?
PS: we tried to install later versions (6.6 and 7.0.0) and we got the same issue.
Form a security point of view, remote CLI access is not enabled by default. You can see this when looking at /lib/systemd/system/varnish.service:
[Unit]
Description=Varnish Cache, a high-performance HTTP accelerator
After=network-online.target nss-lookup.target
[Service]
Type=forking
KillMode=process
# Maximum number of open files (for ulimit -n)
LimitNOFILE=131072
# Locked shared memory - should suffice to lock the shared memory log
# (varnishd -l argument)
# Default log size is 80MB vsl + 1M vsm + header -> 82MB
# unit is bytes
LimitMEMLOCK=85983232
# Enable this to avoid "fork failed" on reload.
TasksMax=infinity
# Maximum size of the corefile.
LimitCORE=infinity
ExecStart=/usr/sbin/varnishd \
-a :6081 \
-a localhost:8443,PROXY \
-p feature=+http2 \
-f /etc/varnish/default.vcl \
-s malloc,256m
ExecReload=/usr/sbin/varnishreload
[Install]
WantedBy=multi-user.target
There are no -T and -S parameters in the standard systemd configuration. However, you can enable this by modifying the systemd configuration yourself.
Just run sudo systemctl edit --full varnish to edit the runtime configuration and add a -T parameter to enable remote CLI access.
Be careful with this and make sure you restrict access to this endpoint via firewalling rules.
Additionally you'll add -S /etc/varnish/secret as a varnishd runtime parameter in /lib/systemd/system/varnish.service.
You can use the following command to add a random unique value to the secret file:
uuidgen | sudo tee /etc/varnish/secret
This is what your runtime parameters would look like:
ExecStart=/usr/sbin/varnishd \
-a :6081 \
-a localhost:8443,PROXY \
-p feature=+http2 \
-f /etc/varnish/default.vcl \
-s malloc,2g \
-S /etc/varnish/secret \
-T :6082
When you're done just run the following command to restart Varnish:
sudo systemctl restart varnish

docker run can't find application

my project structure is:
/docker-test
/app
/static
....
/templates
....
-__init__.py
....
-nginx.conf
-supervisord.conf
-uwsgi.ini
-Dockerfile
-app.py
-requirements.txt
I normally run the app by going into /docker-test>python app.py
Dockerfile:
FROM python:2.7
# Install uWSGI
RUN pip install uwsgi
# Standard set up Nginx
ENV NGINX_VERSION 1.9.11-1~jessie
RUN apt-key adv --keyserver hkp://pgp.mit.edu:80 --recv-keys 573BFD6B3D8FBC641079A6ABABF5BD827BD9BF62 \
&& echo "deb http://nginx.org/packages/mainline/debian/ jessie nginx" >> /etc/apt/sources.list \
&& apt-get update \
&& apt-get install -y ca-certificates nginx=${NGINX_VERSION} gettext-base \
&& rm -rf /var/lib/apt/lists/*
# forward request and error logs to docker log collector
RUN ln -sf /dev/stdout /var/log/nginx/access.log \
&& ln -sf /dev/stderr /var/log/nginx/error.log
EXPOSE 80 443
# Finished setting up Nginx
# Make NGINX run on the foreground
RUN echo "daemon off;" >> /etc/nginx/nginx.conf
# Remove default configuration from Nginx
RUN rm /etc/nginx/conf.d/default.conf
# Copy the modified Nginx conf
COPY nginx.conf /etc/nginx/conf.d/
# Copy the base uWSGI ini file to enable default dynamic uwsgi process number
COPY uwsgi.ini /etc/uwsgi/
# Install Supervisord
RUN apt-get update && apt-get install -y supervisor \
&& rm -rf /var/lib/apt/lists/*
# Custom Supervisord config
COPY supervisord.conf /etc/supervisor/conf.d/supervisord.conf
COPY . /deploy
WORKDIR /deploy
RUN pip install -r /deploy/requirements.txt
CMD ["/usr/bin/supervisord"]
app.py:
#!flask/bin/python
from app import app
from flask import url_for
if __name__ == '__main__':
app.run(host='0.0.0.0', debug=True, port=80)
app.add_url_rule('/favicon.ico', edirect_to=url_for('static', filename='favicon.ico'))
supervidord.conf:
[supervisord]
nodaemon=true
[program:uwsgi]
command=/usr/local/bin/uwsgi --ini /etc/uwsgi/uwsgi.ini --ini /deploy/uwsgi.ini
stdout_logfile=/dev/stdout
stdout_logfile_maxbytes=0
stderr_logfile=/dev/stderr
stderr_logfile_maxbytes=0
[program:nginx]
command=/usr/sbin/nginx
stdout_logfile=/dev/stdout
stdout_logfile_maxbytes=0
stderr_logfile=/dev/stderr
stderr_logfile_maxbytes=0
nginx.conf:
server {
location / {
include uwsgi_params;
uwsgi_pass unix:///tmp/uwsgi.sock;
}
}
uwsgi.ini:
[uwsgi]
wsgi-file=/app.py
socket = /tmp/uwsgi.sock
chown-socket = nginx:nginx
chmod-socket = 664
cheaper = 2
processes = 16
I am able to docker build and run without issue.
I get 500 error when trying to access the app in chrome:
no python application found
What is your current working directory? This just sounds like wsgi-file=/app.py should be wsgi-file=./app.py or you need to reference the correct absolute location such as wsgi-file=/deploy/app/app.py.

WordPress Docker Proxy Error 502 : The proxy server received an invalid response from an upstream server

Working on WordPress, We put a project on docker.
I had a 502 proxy error. I was able to fix it restarting docker. However, the problem is still here on coworkers installation.
I try to fix it. However, I can not recreate the bug, so I have no log for this error.
Here is the dockerfile:
FROM debian:8
MAINTAINER xxxxxxxxxxxxx
LABEL version="1.0"
LABEL description="Debian 8 / Apache 2 / PHP 5"
ARG DEBIAN_FRONTEND=noninteractive
ENV DOCKER_CONTAINER_APP=/var/www
RUN apt-get -y update && apt-get install -y \
apache2 \
php5 \
libapache2-mod-php5 \
mysql-server \
php5-mysql \
supervisor \
phpmyadmin
RUN sed -i -e"s/^bind-address\s*=\s*127.0.0.1/bind-address = 0.0.0.0/" /etc/mysql/my.cnf
RUN /usr/sbin/mysqld & \
sleep 10s &&\
echo "GRANT ALL ON *.* TO admin#'%' IDENTIFIED BY 'heliopsis' WITH GRANT OPTION; FLUSH PRIVILEGES" | mysql
EXPOSE 3306
CMD ["/usr/bin/mysqld_safe"]
COPY ressources/supervisord.conf /etc/supervisor/conf.d/supervisord.conf
COPY ressources/my.cnf /etc/mysql/my.cnf
COPY ressources/init.sql /tmp/init.sql
RUN /etc/init.d/mysql start && mysql -uroot < /tmp/init.sql && /etc/init.d/mysql stop
COPY sql-dumps /tmp/sql-dumps
RUN /etc/init.d/mysql start && gunzip < /tmp/sql-dumps/dump.sql.gz | mysql -uroot -D nalian-local && /etc/init.d/mysql stop
RUN /etc/init.d/mysql start && mysql -uroot -e "SET PASSWORD = PASSWORD('heliopsis');" && /etc/init.d/mysql stop
# Dev env : show errors
RUN sed -i -e 's/^error_reporting\s*=.*/error_reporting = E_ALL/' /etc/php5/apache2/php.ini
RUN sed -i -e 's/^display_errors\s*=.*/display_errors = On/' /etc/php5/apache2/php.ini
RUN a2enmod rewrite
RUN mkdir /etc/apache2/ssl
COPY ressources/vhost /etc/apache2/sites-available/000-default.conf
RUN a2ensite 000-default
# add our local files in docker instance
ADD . $DOCKER_CONTAINER_APP
# add the docker instance as a volume
VOLUME $DOCKER_CONTAINER_APP
# define the workspace of the container
WORKDIR $DOCKER_CONTAINER_APP
# launching apache # startup
CMD cd wp-content; tar xzf $DOCKER_CONTAINER_APP/ressources/uploads.tar.gz; cd ..; ln -s wp-config-dev.php wp-config.php; ln -s htaccess_dev .htaccess;/usr/bin/supervisord
The install-vhost.sh :
#!/usr/bin/env bash
if [ -z "$1" ]
then
echo "dev name required"
exit
fi
if [ -z "$2" ]
then
echo "HTTP port required"
exit
fi
VHOST_TEMPLATE=`find . -name "*.DEV.rocks.conf"`
VHOST=`echo $VHOST_TEMPLATE | sed 's/.*\///' | sed "s/DEV/$1/"`
sudo cat $VHOST_TEMPLATE | replace "DEV" "$1" | replace "PORT" "$2" > /etc/apache2/sites-available/$VHOST
sudo a2ensite $VHOST
sudo service apache2 restart
And the vhost :
############## www.nalian.coralie.rocks
<VirtualHost *:80>
ServerName www.nalian.coralie.rocks
<Proxy *>
Allow from localhost
</Proxy>
ProxyPass / http://localhost:1250/
ProxyPassReverse / http://localhost:1250/
ProxyPreserveHost On
</VirtualHost>
Do you have any idea to help me?

Docker's container mount folder

I am new to Docker and I am trying to simply launch an nginx app.
To do this, I have this DockerFile:
FROM debian:wheezy
MAINTAINER John Regan <john#jrjrtech.com>
RUN echo "deb http://nginx.org/packages/debian/ wheezy nginx" >> /etc/apt/sources.list.d/nginx.list
RUN apt-key adv --fetch-keys "http://nginx.org/keys/nginx_signing.key"
RUN apt-get update && apt-get -y dist-upgrade
RUN apt-get -y install nginx openssl ca-certificates
##Delete default repository
RUN rm -rf /etc/nginx/conf.d/*
RUN rm -rf /srv/www/*
ADD conf/nginx.conf /etc/nginx/nginx.conf
ADD conf/conf.d/default.conf /etc/nginx/conf.d/default.conf
ADD html/index.html /srv/www/index.html
VOLUME ["/etc/nginx"]
VOLUME ["/srv/www"]
EXPOSE 80
EXPOSE 443
ENTRYPOINT ["nginx"]
CMD []
My folder is organise like this:
├── conf
| ├── nginx.conf
| └── conf.d
| └── default.conf
├── html
| └── index.html
The command to launch the container:
sudo docker run -d -p 80:80 -v $pwd/conf:/etc/nginx -v $pwd/html:/srv/www my-nginx
But the conatiner stop and I got this message in the log:
nginx: [emerg] open() "/etc/nginx/mime.types" failed (2: No such file or directory) in /etc/nginx/nginx.conf:14
I know that the log is pretty clear, but I can't figure out why it doesn't work.
Thanks.
When you are mounting your conf dir your are replacing the contents of the /etc/nginx dir. instead mount the nginx.conf file and the conf/conf.d - see the section on mounting files, https://docs.docker.com/v1.8/userguide/dockervolumes/
sudo docker run -d -p 80:80 -v $pwd/conf/conf.d:/etc/nginx/conf.d -v $pwd/conf/nginx.conf:/etc/nginx/nginx.conf -v $pwd/html:/srv/www my-nginx
Are you sure the configuration on the in the nginx.conf is correct? The error seems related to nginx not to the docker.
The "volume" option, mount a new point of directory, you should've specifics if you need mount only a file.

Docker and Analytics Install

I have a docker file called quasar.dockerfile. I built the docker file and everything loaded successfully.
#quasar.dockerfile
FROM java:8
WORKDIR /app
ADD docker/quasar-config.json quasar-config.json
RUN apt-get update && \
apt-get install -y wget && \
wget https://github.com/quasar-analytics/quasar/releases/download/v2.3.3-SNAPSHOT-2121-web/web_2.11-2.3.3-SNAPSHOT-one-jar.jar
EXPOSE 8080
CMD java -jar web_2.11-2.2.3-SNAPSHOT-one-jar.jar -c /app/quasar-config.json
I then tried running the docker and I get this error saying that I am unable to access the jarfile.
[test]$ docker build -f docker/quasar.dockerfile -t quasar_fdw_test/quasar .
Sending build context to Docker daemon 1.851 MB
Successfully built a7d4bc6c906f
[test]$ docker run -d --name quasar_fdw_test-quasar --link quasar_fdw_test-mongodb:mongodb quasar_fdw_test/quasar
6af2f58bf446560507bdf4a2db8ba138de9ed94a408492144e7fdf6c1fe05118
[test]$ docker ps -l
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
6af2f58bf446 quasar_fdw_test/quasar "/bin/sh -c 'java -ja" 5 seconds ago Exited (1) 4 seconds ago quasar_fdw_test- quasar
[test]$ docker logs 6af2f58bf446
Error: Unable to access jarfile web_2.11-2.2.3-SNAPSHOT-one-jar.jar
How come the process keeps getting killed? Seems like it has to do with being unable to run the jarfile but the build needed to access that file and happened successfully. Is this a linking issue?
Try to use full path on Dockerfile
CMD java -jar /web_2.11-2.2.3-SNAPSHOT-one-jar.jar -c /app/quasar-config.json

Resources