Docker Alpine nginx 403 Forbidden error for swagger-ui-builder - nginx

This happened on Ubuntu 16.04 in VirtualBox on Windows 10, with docker version 1.12.1, and swagger-ui version 2.2.2.
I was trying to build and run Swagger UI in a docker container, following the instructions on their site:
docker build -t swagger-ui-builder .
docker run -p 127.0.0.1:8080:8080 swagger-ui-builder
The instruction says that now I should be able to view the swagger-ui running, however, when I opened 127.0.0.1:8080 I only got this page back:
<html>
<head><title>403 Forbidden</title></head>
<body bgcolor="white">
<center><h1>403 Forbidden</h1></center>
<hr><center>nginx/1.8.1</center>
</body>
</html>
This is the content of the Dockerfile:
FROM alpine:3.3
MAINTAINER Roman Tarnavski
RUN apk add --update nginx
COPY nginx.conf /etc/nginx/
ADD ./dist/ /usr/share/nginx/html
EXPOSE 8080
CMD nginx -g 'daemon off;'
I found similar posts on stackoverflow, but none of them helped me solve this problem. What am I doing wrong and how to fix this?

The problem was caused by a permission requirement: the www-data user/group did not have access to website's directory and files.
This problem was explained in the accepted answer to this post: Nginx 403 forbidden for all files
To solve this, the following lines have to be added to the Dockerfile:
RUN set -x ; \
addgroup -g 82 -S www-data ; \
adduser -u 82 -D -S -G www-data www-data && exit 0 ; exit 1
RUN chown -R www-data:www-data /usr/share/nginx/html/*
RUN chmod -R 0755 /usr/share/nginx/html/*
The upper part of the commands are explained in this gist: https://gist.github.com/briceburg/47131d8caf235334b6114954a6e64922
The user/group www-data has to be added first, before the permission can be set for it. The snippet notes that 82 is the standard uid/gid for "www-data" in Alpine
The lower part of the commands is the solution to a similar question in another forum: https://www.digitalocean.com/community/questions/nginx-403-forbidden--2
So the fixed Dockerfile would look like this:
FROM alpine:3.3
MAINTAINER Roman Tarnavski
RUN apk add --update nginx
COPY nginx.conf /etc/nginx/
ADD ./dist/ /usr/share/nginx/html
RUN set -x ; \
addgroup -g 82 -S www-data ; \
adduser -u 82 -D -S -G www-data www-data && exit 0 ; exit 1
RUN chown -R www-data:www-data /usr/share/nginx/html/*
RUN chmod -R 0755 /usr/share/nginx/html/*
EXPOSE 8080
CMD nginx -g 'daemon off;'
Now if I rebuild and rerun swagger-ui-builder, the website shows up correctly.

Related

403 error on configuring new wordpress install

I am using Apache2 and ubuntu. Before my attempt to install wordpress on my server, i was able to open my domain in browser. But after the commands that i wrote below, i can not open it. When i browse my domain it is giving 403 error
Forbidden You don't have permission to access this resource.
I used the commands below while i was installing wordpress. And now, i am wondering how to fix this situation. And which files or other things should i check. Thank you.
First Commands That I Used For In My Terminal
wget http://wordpress.org/latest.tar.gz
tar -xzvf latest.tar.gz
mysql -u root -p
CREATE DATABASE wordpress; Query OK, 1 row affected (0.00 sec)
CREATE USER wordpressuser#localhost; Query OK, 0 rows affected (0.00 sec)
SET PASSWORD FOR wordpressuser#localhost= PASSWORD("password"); Query OK, 0 rows affected (0.00 sec)
GRANT ALL PRIVILEGES ON wordpress.* TO wordpressuser#localhost IDENTIFIED BY 'password'; Query OK, 0 rows affected (0.00 sec)
FLUSH PRIVILEGES; Query OK, 0 rows affected (0.00 sec)
cp ~/wordpress/wp-config-sample.php ~/wordpress/wp-config.php
sudo nano ~/wordpress/wp-config.php
// ** MySQL settings - You can get this info from your web host ** // /** The name of the database for WordPress */ define('DB_NAME', 'wordpress'); /** MySQL database username */ define('DB_USER', 'wordpressuser'); /** MySQL database password */ define('DB_PASSWORD', 'password');
sudo rsync -avP ~/wordpress/ /var/www/
cd /var/www/
sudo chown username:www-data /var/www -R sudo chmod g+w /var/www -R
sudo apt-get install php5-gd
As These Commands Above Didnt Work for me I used Other Commands Below After Deleting Wordpress Directory
cd /var/www/html
sudo wget https://wordpress.org/latest.tar.gz
sudo tar xvfz latest.tar.gz
sudo chown www-data.www-data wordpress/
Those Commands Also Didnt Work For Me So I Added The Other Ones Below
sudo mkdir -p /var/www/html/example.com/src/
cd /var/www/html/example.com/src/
chmod 755 /var/www/html
chmod 750 /var/www
sudo chown -R www-data:www-data /var/www/html/example.com/
sudo wget http://wordpress.org/latest.tar.gz
sudo -u www-data tar -xvf latest.tar.gz
sudo mv latest.tar.gz wordpress-`date "+%Y-%m-%d"`.tar.gz
sudo mkdir /var/www/html/example.com/public_html/
sudo mv wordpress/* ../public_html/
sudo chown -R www-data:www-data /var/www/html/example.com/public_html
These are the access and error logs in my apache2. Which one should i paste?
access and error files in apache2
I replicated your steps on Ubuntu 20.04.3 LTS and it works fine. Here are my steps.
sudo su
apt install apache2
apt install mysql-server
wget http://wordpress.org/latest.tar.gz
tar -xzvf latest.tar.gz
rsync -avP ./wordpress/ /var/www/html
cd /var/www/html
rm index.html
apt install php-mysql
mysql
mysql> CREATE DATABASE wordpress;
mysql> CREATE USER wordpressuser#localhost;
mysql> ALTER USER wordpressuser#localhost IDENTIFIED BY 'pass';
mysql> GRANT ALL PRIVILEGES ON wordpress.* TO wordpressuser#localhost ;
mysql> FLUSH PRIVILEGES;
systemctl restart apache2
If it doesn't work please paste your /var/log/apache2/error.log, your os-release and output of php -v.

Unable to uninstall nginx on Mac OS X

Output of nginx -v:
nginx version: nginx/1.14.0.
After running brew uninstall nginx or brew remove nginx, it gives error:
Error: No such keg: /usr/local/Cellar/nginx
I have tried :
rm -f /usr/local/sbin/nginx
rm -f -R /usr/local/etc/nginx
rm -r /usr/local/opt/nginx
But still nginx -v giving output: nginx version: nginx/1.14.0
How can I remove the nginx installation?
Check path with which nginx Then, you can remove from that path.
Update your local filesystem db on Mac, this will take of any links in the system,
sudo /usr/libexec/locate.updatedb

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

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).

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.

Nginx & Varnish connection error

My site gives error 521 all the times.
When I found this error from my server
$sudo service varnish reload
* Reloading HTTP accelerator varnishd
Connection failed (localhost:6082)
Error: vcl.load 8d6fb6be-9a0a-4896-be47-e2678e3c2617 /etc/varnish/default.vcl failed
Moreover,
varnishlog
shows nothing.
I am following this tutorial to set the server up. And, I changed
DAEMON_OPTS="-a :80 \
-T localhost:6082 \
-f /etc/varnish/default.vcl \
-u www-data -g www-data \
-S /etc/varnish/secret \
-s malloc,256m"
The /etc/varnish/default.vcl file is copied from the tutorial. All & has been corrected to &.
It is a fresh VPS. No firewall.
Any clue to resolve it?
Thanks!!!!
3 things come into my mind:
Start varnish in foreground mode and check what it says
varnishd -F -a :80 \
-T localhost:6082 \
-f /etc/varnish/default.vcl \
-u www-data -g www-data \
-S /etc/varnish/secret \
-s malloc,256m
Try changing -T localhost:6082 to -T 127.0.0.1:6082
Your port 6082 might be already taken. Change it or check if it's listed in already open ports' list with
netstat -tlnep
restart your varnish
sudo /etc/init.d/varnish restart
then
sudo /etc/init.d/varnish reload

Resources