Nginx (Build From Source) On Ubuntu 14.04 x64? - nginx

I am a newB to setting up NGINX from source and every .sh configuration I try has errors of some type - I have been at this for days! - LOL
I am needing a set up with pageSpeed, OppenSSL, SPDY and Naxsi mods at minimum to drive an equal amount of static and dynamically php files on the site.
Below is my latest attempt that I put together but I get ".configure command not found" :P
If anyone can go thru it ( I am not sure about the dependencies either) and see what I have wrong?? Also any suggestions would also be greatly appreciated. Thnx!
# Since I am not going to be using a distribution to install Nginx,
# I need to ensure all the necessary dependencies are installed for it
# as well as for PageSpeed and SPDY:
sudo apt-get install build-essential zlib1g-dev libpcre3 libpcre3-dev libbz2-dev libssl-dev tar unzip openssl
# create a directory root directory called src to download all the filles to,
# including Nginx:
sudo mkdir src
cd src
# NGINX
wget http://nginx.org/download/nginx-1.7.4.tar.gz
tar -xvzf nginx-1.7.4.tar.gz
# Google PageSpeed:
wget https://github.com/pagespeed/ngx_pagespeed/archive/release-1.8.31.4-beta.zip
unzip release-1.8.31.4-beta.zip
cd ngx_pagespeed-release-1.8.31.4-beta/
wget https://dl.google.com/dl/page-speed/psol/1.8.31.4.tar.gz
sudo tar -xzvf 1.8.31.4.tar.gz
# Switch back to src directory
cd
cd src
# HTTP Substitutions Module:
wget https://github.com/arut/nginx-dav-ext-module/archive/master.zip
unzip master.zip
# Now let’s grab the Headers More Mod:
wget https://github.com/agentzh/headers-more-nginx-module/archive/v0.25.tar.gz
tar -xvzf v0.25.tar.gz
# and the naxsi module:
wget https://github.com/nbs-system/naxsi/archive/0.53-2.tar.gz
tar -xvzf 0.53-2.tar.gz
# cd to the uncompresses Nginx directory
cd
cd nginx-1.7.4
# Run a .configure command:
.configure \
--add-module=/src/naxsi-0.53-2 \
--prefix=/usr/share/nginx \
--conf-path=/etc/nginx/nginx.conf \
--error-log-path=/var/log/nginx/error.log \
--user=www-data \
--group=www-data \
--http-client-body-temp-path=/var/lib/nginx/body \
--http-fastcgi-temp-path=/var/lib/nginx/fastcgi \
--http-log-path=/var/log/nginx/access.log \
--http-proxy-temp-path=/var/lib/nginx/proxy \
--http-scgi-temp-path=/var/lib/nginx/scgi \
--http-uwsgi-temp-path=/var/lib/nginx/uwsgi \
--lock-path=/var/lock/nginx.lock \
--pid-path=/run/nginx.pid \
--with-pcre-jit \
--with-debug \
--with-http_addition_module \
--with-http_dav_module \
--with-http_geoip_module \
--with-http_gzip_static_module \
--with-http_image_filter_module \
--with-http_realip_module \
--with-http_stub_status_module \
--with-http_ssl_module \
--with-http_sub_module \
--with-http_xslt_module \
--with-ipv6 \
--with-http_spdy_module \
--add-module=/src/nginx-dav-ext-module-master \
--add-module=/src/ngx_http_substitutions_filter_module \
--add-module=/src/ngx_pagespeed-release-1.8.31.4-beta \
--add-module=/src/headers-more-nginx-module-0.25
# Now create the Makefile:
make

Are you sure it's not a typo? It should be ./configure (not .configure).

Related

Nginx: Hide server signature

I have read a lot of questions on StackOverflow. For many people they were helpful, but for me not.
I need to hide the server name, or at least change it.
I wrote a docker file, to download a dynamic module and inject it into the configuration in the next step.
ARG VERSION=alpine
FROM nginx:${VERSION} as builder
ENV MORE_HEADERS_VERSION=0.34
ENV MORE_HEADERS_GITREPO=openresty/headers-more-nginx-module
RUN wget "http://nginx.org/download/nginx-${NGINX_VERSION}.tar.gz" -O nginx.tar.gz && \
wget "https://github.com/${MORE_HEADERS_GITREPO}/archive/v${MORE_HEADERS_VERSION}.tar.gz" -O extra_module.tar.gz
RUN apk add --no-cache --virtual .build-deps \
gcc \
libc-dev \
make \
openssl-dev \
pcre-dev \
zlib-dev \
linux-headers \
libxslt-dev \
gd-dev \
geoip-dev \
perl-dev \
libedit-dev \
mercurial \
bash \
alpine-sdk \
findutils
SHELL ["/bin/ash", "-eo", "pipefail", "-c"]
RUN rm -rf /usr/src/nginx /usr/src/extra_module && mkdir -p /usr/src/nginx /usr/src/extra_module && \
tar -zxC /usr/src/nginx -f nginx.tar.gz && \
tar -xzC /usr/src/extra_module -f extra_module.tar.gz
WORKDIR /usr/src/nginx/nginx-${NGINX_VERSION}
RUN CONFARGS=$(nginx -V 2>&1 | sed -n -e 's/^.*arguments: //p') && \
sh -c "./configure --with-compat $CONFARGS --add-dynamic-module=/usr/src/extra_module/*" && make modules
FROM nginx:${VERSION}
COPY --from=builder /usr/src/nginx/nginx-${NGINX_VERSION}/objs/*_module.so /etc/nginx/modules/
COPY devops/nginx/nginx.conf /etc/nginx/
EXPOSE 81 82
CMD ["nginx", "-g", "daemon off;"]
Then, I added the module into the nginx.conf file. (I also tried to load the module without "")
load_module "modules/ngx_http_headers_more_filter_module.so";
And finally, I wrote into http block
http{
more_clear_headers server;
more_set_headers "server: hidden";
server_tokens off;
proxy_pass_header server; //Tried to add it for reverse proxying, but it did not work
}
Only server_tokens off; works. I have removed nginx version, but not it's signature. more_clear_headers and more_set_headers do not affect it. What am I missing?
P.s. Checked the modules folder in the server, and my module loaded correctly
P.p.s. Tried Server with capital S, and it did not work either. (As many suggested, but my response returns it with lowercase)

Can I completely customize the flags for ./configure in a SPEC file?

My rpmbuild log tells me all the flags used when calling configure:
./configure --build=x86_64-redhat-linux-gnu --host=x86_64-redhat-linux-gnu \
--program-prefix= \
--disable-dependency-tracking \
--prefix=/usr \
--exec-prefix=/usr \
--bindir=/usr/bin \
--sbindir=/usr/sbin \
--sysconfdir=/etc \
--datadir=/usr/share \
--includedir=/usr/include \
--libdir=/usr/lib64 \
--libexecdir=/usr/libexec \
--localstatedir=/var \
--sharedstatedir=/var/lib \
--mandir=/usr/share/man \
--infodir=/usr/share/info \
--prefix=/opt/custom/SENSOR/Qt-5.15.2 \
--confirm-license \
--opensource
My problem is that the 'build' and 'host' flags (plus several others) are unknown commands for this particular configure script. How can I take complete control of the call to configure in my SPEC file? It's obviously not enough to add new flags to the %configure scriptlet, I need to remove flags that rpmbuild is adding by default.
It looks like the answer is to call configure directly instead of using the scriptlet. I.e., replace %configure with:
./configure --prefix=/opt/custom/SENSOR -confirm-license -opensource

Transfer Large Files Asynchronously In Flask

What is the best approach for transfer large files Asynchronously in Flask? I have read this article. But I want to know if there is a way to do this without using celery?
Flask is a synchronous framework, you can try flask+gevent and streaming responses like explained here: http://flask.pocoo.org/docs/0.12/patterns/streaming/.
Anyway, if you want to upload properly very large files, I suggest you to use a different approach. Instead of trying to do asynchronous networking with a synchronous framework try delegating the transfer with Nginx upload_module, like explained here: http://blog.thisisfeifan.com/2013/03/nginx-upload-module-vs-flask.html
Nginx is faster and won't load up the files in memory, a thing that regular frameworks like Flask or Django even in Asynchronous mode will do. Remember to configure flask to receive after upload POST with directive upload_pass. The only caveat is that you'll have to learn how to compile a full fledge Nginx from source, here an example of working Dockerfile:
FROM buildpack-deps:jessie
##### NGINX #####
# Base Stuff
RUN apt-get update && apt-get install -y -qq \
libssl-dev
# Nginx with upload_module and upload_progress_module
# "Stable version".
ENV ZLIB_VERSION 1.2.11
ENV PCRE_VERSION 8.39
ENV NGX_UPLOAD_MODULE_VERSION 2.2
ENV NGX_UPLOAD_PROGRESS_VERSION 0.9.1
ENV NGX_HEADERS_MORE_VERSION 0.32
ENV NGX_SPPEDPAGE_VERSION 1.11.33.4
ENV NGINX_VERSION 1.11.8
RUN cd /tmp \
&& wget http://nginx.org/download/nginx-${NGINX_VERSION}.tar.gz \
&& tar xvf nginx-${NGINX_VERSION}.tar.gz \
&& wget https://github.com/openresty/headers-more-nginx-module/archive/v${NGX_HEADERS_MORE_VERSION}.tar.gz \
&& tar -xzvf v${NGX_HEADERS_MORE_VERSION}.tar.gz \
&& wget https://github.com/pagespeed/ngx_pagespeed/archive/latest-stable.tar.gz \
&& tar -xzvf latest-stable.tar.gz \
&& wget https://dl.google.com/dl/page-speed/psol/${NGX_SPPEDPAGE_VERSION}.tar.gz \
&& tar -xzvf ${NGX_SPPEDPAGE_VERSION}.tar.gz \
&& mv psol ngx_pagespeed-latest-stable/ \
&& git clone -b ${NGX_UPLOAD_MODULE_VERSION} https://github.com/Austinb/nginx-upload-module \
&& wget http://zlib.net/zlib-${ZLIB_VERSION}.tar.gz \
&& tar xvf zlib-${ZLIB_VERSION}.tar.gz \
&& wget ftp://ftp.csx.cam.ac.uk/pub/software/programming/pcre/pcre-${PCRE_VERSION}.tar.bz2 \
&& tar -xjf pcre-${PCRE_VERSION}.tar.bz2 \
&& wget https://github.com/masterzen/nginx-upload-progress-module/archive/v${NGX_UPLOAD_PROGRESS_VERSION}.tar.gz \
&& tar xvf v${NGX_UPLOAD_PROGRESS_VERSION}.tar.gz \
&& cd nginx-${NGINX_VERSION} \
&& ./configure \
--with-pcre=../pcre-${PCRE_VERSION}/ \
--with-zlib=../zlib-${ZLIB_VERSION}/ \
--add-module=../nginx-upload-module \
--add-module=../nginx-upload-progress-module-${NGX_UPLOAD_PROGRESS_VERSION} \
--add-module=../ngx_pagespeed-latest-stable \
--add-module=../headers-more-nginx-module-${NGX_HEADERS_MORE_VERSION} \
--with-select_module \
--with-poll_module \
--with-file-aio \
--with-http_ssl_module \
--with-ipv6 \
--with-pcre-jit \
--with-http_gzip_static_module \
--with-http_ssl_module \
--with-http_v2_module \
--with-http_realip_module \
--user=nginx --group=nginx --sbin-path=/usr/sbin/nginx --conf-path=/etc/nginx/nginx.conf --error-log-path=/var/log/nginx/error.log --http-log-path=/var/log/nginx/access.log --pid-path=/var/run/nginx.pid --with-cpu-opt=CPU -- with-ld-opt="-Wl,-E" \
&& make \
&& make install
EXPOSE 80 443
CMD ["nginx", "-g", "daemon off;"]
NOTE: Please in this image is lacking the provision of nginx.conf and default.conf.

Symfony 3 and Docker (nginx, php7.1-fpm mysql8) Performances low on Windows

I'm using Docker to work on Symfony 3 project, Here is the following stack :
-Custom Php7.1FPM here's the DockerFile :
FROM php:7.1.0-fpm
MAINTAINER xxxxx xxxxxx <xxxx.xxxxxx#gmail.com>
ENV PHP_APCU_VERSION 5.1.8
ENV PHP_XDEBUG_VERSION 2.5.0
RUN apt-get update \
&& apt-get install -y \
libicu-dev \
zlib1g-dev \
&& docker-php-source extract \
&& curl -L -o /tmp/apcu-$PHP_APCU_VERSION.tgz https://pecl.php.net/get/apcu-$PHP_APCU_VERSION.tgz \
&& curl -L -o /tmp/xdebug-$PHP_XDEBUG_VERSION.tgz http://xdebug.org/files/xdebug-$PHP_XDEBUG_VERSION.tgz \
&& tar xfz /tmp/apcu-$PHP_APCU_VERSION.tgz \
&& tar xfz /tmp/xdebug-$PHP_XDEBUG_VERSION.tgz \
&& rm -r \
/tmp/apcu-$PHP_APCU_VERSION.tgz \
/tmp/xdebug-$PHP_XDEBUG_VERSION.tgz \
&& mv apcu-$PHP_APCU_VERSION /usr/src/php/ext/apcu \
&& mv xdebug-$PHP_XDEBUG_VERSION /usr/src/php/ext/xdebug \
&& docker-php-ext-install \
apcu \
intl \
mbstring \
mysqli \
xdebug \
zip \
&& pecl install apcu_bc-1.0.3 \
&& docker-php-source delete \
&& php -r "readfile('https://getcomposer.org/installer');" | php -- --install-dir=/usr/local/bin --filename=composer \
&& chmod +x /usr/local/bin/composer
last nginx image
mysql:8.0.0
I use docker-compose to build those 3 containers, here's the docker-compose.yml :
front:
image: nginx
ports:
- "81:80"
links:
- "engine:engine"
volumes:
- ".:/home/docker:ro"
- "./docker/front/default.conf:/etc/nginx/conf.d/default.conf:ro"
engine:
build: ./docker/engine/
volumes:
- ".:/home/docker:rw"
- "./docker/engine/php.ini:/usr/local/etc/php/conf.d/custom.ini:ro"
links:
- "db:db"
working_dir: "/home/docker"
db:
image: mysql:8.0.0
ports:
- "3306:3306"
environment:
- MYSQL_ROOT_PASSWORD=pwd
- MYSQL_USER=myUSer
- MYSQL_PASSWORD=pwd
- MYSQL_DATABASE=bddProject
The first time without cache the time is 1700 ms :
And the time with cache is :
The half time is initialisation time :
So What kind of problem could slow the page render of my project ?
Docker last version and 2 Go with Windows Hyper-v system.
Thank you for your help.
So i make an other image without xdebug ant the result is the same
(700ms with cache) :
My DockerFile :
FROM php:7.1.0-fpm
MAINTAINER XXXXX XXXXXX <XXXXXX.XXXXXX#gmail.com>
ENV PHP_APCU_VERSION 5.1.8
RUN apt-get update \
&& apt-get install -y \
libicu-dev \
zlib1g-dev \
&& docker-php-source extract \
&& curl -L -o /tmp/apcu-$PHP_APCU_VERSION.tgz https://pecl.php.net/get/apcu-$PHP_APCU_VERSION.tgz \
&& tar xfz /tmp/apcu-$PHP_APCU_VERSION.tgz \
&& rm -r \
/tmp/apcu-$PHP_APCU_VERSION.tgz \
&& mv apcu-$PHP_APCU_VERSION /usr/src/php/ext/apcu \
&& docker-php-ext-install \
apcu \
intl \
mbstring \
mysqli \
zip \
&& pecl install apcu_bc-1.0.3 \
&& docker-php-source delete \
&& php -r "readfile('https://getcomposer.org/installer');" | php -- --install-dir=/usr/local/bin --filename=composer \
&& chmod +x /usr/local/bin/composer
So it's the window's management of Docker volume which make that, so #Geoffrey Brier you know if Microsoft has planned to improve this performance problem ?
Is there a soft or other to improve that ?
Thank you for your help.
As far as I can see there are two things that are responsible for those performances :
Xdebug
Windows : it's no troll but it's a well known problem that the way your containers volumes are handled by Docker on Windows is not as efficient as on Linux.
You have three solutions : struggle to find a method that slightly improves the performances, use Linux (in a VM for instance) or deal with it :)

How to set up SPDY Protocol over Nginx?

I have a rails app and want to set up the google SPDY protocol support. But after installing Nginx with SPDY patch and then enabling the spdy in virtual host it does not allow me to restart the nginx instead throws following error.
Restarting nginx: nginx: [emerg] invalid parameter "spdy" in /etc/nginx/sites-enabled/default:112
nginx: configuration file /etc/nginx/nginx.conf test failed
I have compiled latest nginx 1.3.13 with spdy patch, here I am mentioning my steps of install
wget http://nginx.org/download/nginx-1.3.13.tar.gz
tar xvfz nginx-1.3.13.tar.gz
cd nginx-1.3.13
# Fetch the SPDY patch and apply it
wget http://nginx.org/patches/spdy/patch.spdy.txt
patch -p1 < patch.spdy.txt
./configure \
--sbin-path=/usr/local/sbin/nginx \
--prefix=/etc/nginx \
--conf-path=/etc/nginx/nginx.conf \
--error-log-path=/var/log/nginx/error.log \
--http-client-body-temp-path=/var/lib/nginx/body \
--http-fastcgi-temp-path=/var/lib/nginx/fastcgi \
--http-log-path=/var/log/nginx/access.log \
--http-proxy-temp-path=/var/lib/nginx/proxy \
--http-scgi-temp-path=/var/lib/nginx/scgi \
--http-uwsgi-temp-path=/var/lib/nginx/uwsgi \
--lock-path=/var/lock/nginx.lock \
--pid-path=/var/run/nginx.pid \
--with-debug \
--with-http_addition_module \
--with-http_dav_module \
--with-http_gzip_static_module \
--with-http_realip_module \
--with-http_stub_status_module \
--with-http_ssl_module \
--with-http_sub_module \
--with-http_xslt_module \
--with-http_spdy_module \
--with-ipv6 \
--with-sha1=/usr/include/openssl \
--with-md5=/usr/include/openssl \
--with-mail \
--with-mail_ssl_module \
# wget https://you.googlecode.com/files/ngx_cache_purge-1.6.tar.gz
--add-module=/software/ngx_cache_purge-1.6 \
#http://www.openssl.org/source/openssl-1.0.1e.tar.gz
--with-openssl='/software/openssl-1.0.1e'
# Build and install nginx
make && sudo make install
It compiles successfully without any error.
Result 0f nginx -V gives following
nginx version: nginx/1.3.13
built by gcc 4.6.3 (Ubuntu/Linaro 4.6.3-1ubuntu5)
TLS SNI support enabled
configure arguments: --sbin-path=/usr/local/sbin/nginx --prefix=/etc/nginx --conf- path=/etc/nginx/nginx.conf --error-log-path=/var/log/nginx/error.log --http-client-body-temp-path=/var/lib/nginx/body --http-fastcgi-temp-path=/var/lib/nginx/fastcgi --http-log-path=/var/log/nginx/access.log --http-proxy-temp-path=/var/lib/nginx/proxy --http-scgi-temp-path=/var/lib/nginx/scgi --http-uwsgi-temp-path=/var/lib/nginx/uwsgi --lock-path=/var/lock/nginx.lock --pid-path=/var/run/nginx.pid --with-debug --with-http_addition_module --with-http_dav_module --with-http_gzip_static_module --with-http_realip_module --with-http_stub_status_module --with-http_ssl_module --with-http_sub_module --with-http_xslt_module --with-http_spdy_module --with-ipv6 --with-sha1=/usr/include/openssl --with-md5=/usr/include/openssl --with-mail --with-mail_ssl_module --add-module=/software/ngx_cache_purge-1.6 --with-openssl=/software/openssl-1.0.1e
My /etc/nginx/site-enabled config has
server {
listen 443 ssl spdy;
ssl_certificate server.crt;
ssl_certificate_key server.key;
...
}
After all this successfull installation nginx does not restart with spdy param in server block of site-enabled file.
Any suggestions? I am sure of missing something here but can't figure out.
UPDATE (November 19th, 2013): Modified script for nginx 1.4.3 (Does not need spdy patch)
https://gist.github.com/deepak-kumar/7541199#file-compile_nginx_1-4-3_with-spdy-sh
I wrote Shell Script for the setup
https://gist.github.com/deepak-kumar/5069550#file-compile_nginx_with_spdy-sh
I have found the solution to the problem.
I already had nginx package installed on my ubuntu 12.04 even before compiling this 1.3.13 which was causing the problem.$ sudo apt-get install nginx
To solve this issue I made sure that /etc/init.d/nginx should use the correct binary.
I did following on terminal:
$ which nginx
$ /usr/local/sbin/nginx
Checked my existing /etc/init.d/nginx script it was using wrong DAEMON path so I changed it to look like this (works)
PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
DAEMON=/usr/local/sbin/nginx # $which nginx
Earlier above values were (does not work)
#PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
#DAEMON=/usr/sbin/nginx
Rest of the file remains same. So essentially I used the correct version binary.
Update: This blog is also a very good reference point in case you guys are interested.
http://blog.bubbleideas.com/2012/08/How-to-set-up-SPDY-on-nginx-for-your-rails-app-and-test-it.html

Resources