NGINX („engine X“) installieren

      Keine Kommentare zu NGINX („engine X“) installieren

Den Webserver NGINX auf dem Raspberry Pi installieren:

NGINX ist eine schlanke Webserver-Alternative und bietet die Möglichkeit einen Websocket-Proxy einzurichten. Davon soll in Kombination mit NODEJS Gebrauch gemacht werden. Eine Installationsanleitung für NODEJS findet sich hier: INSTALL NODEJS

Um NGINX als WebSocket Proxy verwenden zu können muss eine Version >= 1.3 verwendet werden. Ältere Wheezy Raspbian Versionen installieren noch eine Version 1.2 – damit funktioniert der WebSocket Proxy nicht.

  1. Herausfinden welche Version über apt-get installiert weden würde:
  2. pi@raspberrypi:/ $ sudo apt-cache show nginx
    Package: nginx
    Version: 1.6.2-5+deb8u1
    Installed-Size: 99
    Maintainer: Kartik Mistry <kartik@debian.org>
    Architecture: all
    Depends: nginx-full (>= 1.6.2-5+deb8u1) | nginx-light (>= 1.6.2-5+deb8u1) | nginx-extras (>= 1.6.2-5+deb8u1), nginx-full (<< 1.6.2-5+deb8u1.1~) | nginx-light (<< 1.6.2-5+deb8u1.1~) | nginx-extras (<< 1.6.2-5+deb8u1.1~)
    Size: 72160
    SHA256: 9d6ba6127ebc251e4ba869f79dba8b335ce830f5ae2429c6c83d85af234aa4a1
    SHA1: 21ed85cf00bdffc9a7d717990a6cfc142b20eb67
    MD5sum: b1d4df4d05cc0f536dd1639e3e58b7cf
    Description: small, powerful, scalable web/proxy server
     Nginx ("engine X") is a high-performance web and reverse proxy server
     created by Igor Sysoev. It can be used both as a standalone web server
     and as a proxy to reduce the load on back-end HTTP or mail servers.
     .
     This is a dependency package to install either nginx-full (by default) or
     nginx-light.
    Description-md5: fcb68fdad0dca137e47a44b011e92ee4
    Homepage: http://nginx.net
    Section: httpd
    Priority: optional
    Filename: pool/main/n/nginx/nginx_1.6.2-5+deb8u1_all.deb
    
  3. NGINX installieren – hier ist es die Version 1.62, ggf. lohnt sich ein Wechsel von Raspbian Wheezy auf Jessie.
  4. sudo apt-get install nginx
    sudo apt-get install php5-fpm php5-cgi php5-cli php5-common
    
  5. NGINX konfigurieren
  6. sudo nano /etc/nginx/sites-enabled/default

Hier eine exemplarische Beispiel-Konfiguration die lediglich der Veranschaulichung dienen soll:

  • Websocket-Proxy
  • Webserver über Port 80 erreichbar
  • Websocket Server z.B. NODEJS WSS lokal auf dem Port 8010
  • Websocket-Backend z.B.: var wsUrl = ‚ws://‘ + location.hostname + ‚/socket‘;
  • Webserver root Verzeichnis /var/www/html
  • ##
    # You should look at the following URL's in order to grasp a solid understanding
    # of Nginx configuration files in order to fully unleash the power of Nginx.
    # http://wiki.nginx.org/Pitfalls
    # http://wiki.nginx.org/QuickStart
    # http://wiki.nginx.org/Configuration
    #
    # Generally, you will want to move this file somewhere, and start with a clean
    # file but keep this around for reference. Or just disable in sites-enabled.
    #
    # Please see /usr/share/doc/nginx-doc/examples/ for more detailed examples.
    ##
    
    map $http_upgrade $connection_upgrade {
        default upgrade;
        '' close;
    }
    
    upstream websocket {
        server localhost:8010;
    }
    
    
    # Default server configuration
    #
    server {
    	listen 80 default_server;
    	listen [::]:80 default_server;
    
    	# SSL configuration
    	#
    	# listen 443 ssl default_server;
    	# listen [::]:443 ssl default_server;
    	#
    	# Self signed certs generated by the ssl-cert package
    	# Don't use them in a production server!
    	#
    	# include snippets/snakeoil.conf;
    
    	root /var/www/html;
    
    	# Add index.php to the list if you are using PHP
    	index index.html index.htm index.nginx-debian.html;
    
    	server_name _;
    
    	location / {
    		# First attempt to serve request as file, then
    		# as directory, then fall back to displaying a 404.
    		try_files $uri $uri/ =404;
    	}
      
      #websocket TEST 
      location /socket {
        proxy_pass http://websocket;
        proxy_http_version 1.1;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection "Upgrade";
      }
    
    	# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
    	#
    	location ~ \.php$ {
    	#	include snippets/fastcgi-php.conf;
    	#
    	#	# With php5-cgi alone:
    	#	fastcgi_pass 127.0.0.1:9000;
    	#	# With php5-fpm:
    	fastcgi_pass unix:/var/run/php5-fpm.sock;
    	fastcgi_index index.php;
    	include fastcgi_params;
    	}
    
    	# deny access to .htaccess files, if Apache's document root
    	# concurs with nginx's one
    	#
    	#location ~ /\.ht {
    	#	deny all;
    	#}
    }
    
    
    # Virtual Host configuration for example.com
    #
    # You can move that to a different file under sites-available/ and symlink that
    # to sites-enabled/ to enable it.
    #
    #server {
    #	listen 80;
    #	listen [::]:80;
    #
    #	server_name example.com;
    #
    #	root /var/www/example.com;
    #	index index.html;
    #
    #	location / {
    #		try_files $uri $uri/ =404;
    #	}
    #}
    

    Webserver neu starten:

    sudo service nginx restart

    ggf.

    sudo service php5-fpm restart