nginx
Differences
This shows you the differences between two versions of the page.
| Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
| nginx [2015/05/16 17:46] – skipidar | nginx [2023/10/13 16:30] (current) – skipidar | ||
|---|---|---|---|
| Line 1: | Line 1: | ||
| + | ===== nginx ===== | ||
| + | The **nginx** webserver is a fast and powerfull webserver, which usually used in production for loadbalancing. | ||
| + | |||
| + | === Configuraiton PHP+nginx on Windows === | ||
| + | |||
| + | Here is the describiton: | ||
| + | https:// | ||
| + | |||
| + | On Windows7 x64 a lib **Visual C++ Redistributable for Visual Studio 2012 Update 4** has to be installed, for php-cgi.exe to work. | ||
| + | Otherwise it throws an exception | ||
| + | < | ||
| + | |||
| + | **Both versions, 32 and x64** bit have to be installed for the php-cgi to work: \\ | ||
| + | http:// | ||
| + | |||
| + | ==== PHP configuraiton ==== | ||
| + | Php in configured in php.ini. You can check where it should be located by checking the *Configuration File (php.ini) Path* among the output of | ||
| + | <sxh=php > | ||
| + | <?php | ||
| + | | ||
| + | ?> | ||
| + | </ | ||
| + | |||
| + | Alternatively you can pass the php.ini explicitely to the service **php-cgi** which serves the cgi requests. | ||
| + | |||
| + | < | ||
| + | " | ||
| + | </ | ||
| + | |||
| + | |||
| + | ==== nginx.conf ==== | ||
| + | |||
| + | This config redirects all requests with all methods (GET, POST, PUT, DELETE) to the file index.php. | ||
| + | The originally requested path may be retrieved from the **$_SERVER** variable. | ||
| + | The **GET / POST** parameters are available as well. | ||
| + | |||
| + | < | ||
| + | |||
| + | #user nobody; | ||
| + | worker_processes | ||
| + | |||
| + | # | ||
| + | # | ||
| + | # | ||
| + | |||
| + | #pid logs/ | ||
| + | |||
| + | |||
| + | events { | ||
| + | worker_connections | ||
| + | } | ||
| + | |||
| + | |||
| + | http { | ||
| + | include | ||
| + | default_type | ||
| + | |||
| + | sendfile | ||
| + | |||
| + | keepalive_timeout | ||
| + | |||
| + | server { | ||
| + | listen | ||
| + | server_name | ||
| + | |||
| + | # this guy redirects any path to /api.json | ||
| + | rewrite ^.*$ /index.php last; | ||
| + | |||
| + | location / { | ||
| + | root html; | ||
| + | index index.php index.html index.htm; | ||
| + | try_files $uri $uri/ /index.php; | ||
| + | } | ||
| + | |||
| + | # redirect server error pages to the static page /50x.html | ||
| + | error_page | ||
| + | location = /50x.html { | ||
| + | root html; | ||
| + | } | ||
| + | |||
| + | location ~ \.php$ { | ||
| + | root html; | ||
| + | fastcgi_pass | ||
| + | fastcgi_index | ||
| + | fastcgi_param | ||
| + | include | ||
| + | set $path_info | ||
| + | fastcgi_param PATH_INFO $fastcgi_script_name; | ||
| + | } | ||
| + | } | ||
| + | |||
| + | } | ||
| + | |||
| + | </ | ||
| + | |||
| + | |||
| + | To retrieve the requested method do the following inside the **index.php** | ||
| + | |||
| + | < | ||
| + | <?php | ||
| + | echo "hello \n"; | ||
| + | |||
| + | # requested method (PUT GET POST DELETE) | ||
| + | echo getServerVariable(' | ||
| + | |||
| + | # REQUEST_URI as string | ||
| + | $requesturi = getServerVariable(' | ||
| + | echo requesturi . " | ||
| + | |||
| + | # REQUEST_URI as an array of path segments | ||
| + | $requesturiArray = explode('/', | ||
| + | echo implode($requesturiArray) . " | ||
| + | |||
| + | |||
| + | function getServerVariable($variable){ | ||
| + | if(isset($_SERVER[$variable])){ | ||
| + | $pmethod = $_SERVER[$variable]; | ||
| + | return $pmethod; | ||
| + | }else{ | ||
| + | return " | ||
| + | } | ||
| + | } | ||
| + | |||
| + | ?> | ||
| + | </ | ||
| + | |||
| + | |||
| + | Generated config from reverse_proxy nginx | ||
| + | |||
| + | <sxh json> | ||
| + | root@f5ae19524493:/# | ||
| + | # nginx-proxy version : 1.3.0 | ||
| + | # Networks available to the container running docker-gen (which are assumed to | ||
| + | # match the networks available to the container running nginx): | ||
| + | # | ||
| + | # If we receive X-Forwarded-Proto, | ||
| + | # scheme used to connect to this server | ||
| + | map $http_x_forwarded_proto $proxy_x_forwarded_proto { | ||
| + | default $http_x_forwarded_proto; | ||
| + | '' | ||
| + | } | ||
| + | map $http_x_forwarded_host $proxy_x_forwarded_host { | ||
| + | default $http_x_forwarded_host; | ||
| + | '' | ||
| + | } | ||
| + | # If we receive X-Forwarded-Port, | ||
| + | # server port the client connected to | ||
| + | map $http_x_forwarded_port $proxy_x_forwarded_port { | ||
| + | default $http_x_forwarded_port; | ||
| + | '' | ||
| + | } | ||
| + | # If the request from the downstream client has an " | ||
| + | # non-empty value), pass " | ||
| + | # Otherwise, the value for the " | ||
| + | # has enabled keepalive to the upstream server. | ||
| + | map $http_upgrade $proxy_connection { | ||
| + | default upgrade; | ||
| + | '' | ||
| + | } | ||
| + | map $upstream_keepalive $proxy_connection_noupgrade { | ||
| + | # Preserve nginx' | ||
| + | default close; | ||
| + | # Use an empty string to cancel nginx' | ||
| + | true ''; | ||
| + | } | ||
| + | # Abuse the map directive (see < | ||
| + | # that $upstream_keepalive is always defined. | ||
| + | # - The $proxy_connection variable is indirectly derived from | ||
| + | # | ||
| + | # | ||
| + | # - The $proxy_connection variable is used in a proxy_set_header directive in | ||
| + | # the http block, so it is always fully resolved for every request -- even | ||
| + | # those where proxy_pass is not used (e.g., unknown virtual host). | ||
| + | map "" | ||
| + | # The value here should not matter because it should always be overridden in | ||
| + | # a location block (see the " | ||
| + | # value actually matters. | ||
| + | default false; | ||
| + | } | ||
| + | # Apply fix for very long server names | ||
| + | server_names_hash_bucket_size 128; | ||
| + | # Default dhparam | ||
| + | ssl_dhparam / | ||
| + | # Set appropriate X-Forwarded-Ssl header based on $proxy_x_forwarded_proto | ||
| + | map $proxy_x_forwarded_proto $proxy_x_forwarded_ssl { | ||
| + | default off; | ||
| + | https on; | ||
| + | } | ||
| + | gzip_types text/plain text/css application/ | ||
| + | log_format vhost '$host $remote_addr - $remote_user [$time_local] " | ||
| + | access_log off; | ||
| + | ssl_protocols TLSv1.2 TLSv1.3; | ||
| + | ssl_ciphers ' | ||
| + | ssl_prefer_server_ciphers off; | ||
| + | error_log / | ||
| + | resolver 127.0.0.11; | ||
| + | # HTTP 1.1 support | ||
| + | proxy_http_version 1.1; | ||
| + | proxy_buffering off; | ||
| + | proxy_set_header Host $http_host; | ||
| + | proxy_set_header Upgrade $http_upgrade; | ||
| + | proxy_set_header Connection $proxy_connection; | ||
| + | proxy_set_header X-Real-IP $remote_addr; | ||
| + | proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; | ||
| + | proxy_set_header X-Forwarded-Host $proxy_x_forwarded_host; | ||
| + | proxy_set_header X-Forwarded-Proto $proxy_x_forwarded_proto; | ||
| + | proxy_set_header X-Forwarded-Ssl $proxy_x_forwarded_ssl; | ||
| + | proxy_set_header X-Forwarded-Port $proxy_x_forwarded_port; | ||
| + | proxy_set_header X-Original-URI $request_uri; | ||
| + | # Mitigate httpoxy attack (see README for details) | ||
| + | proxy_set_header Proxy ""; | ||
| + | server { | ||
| + | server_name _; # This is just an invalid value which will never trigger on a real hostname. | ||
| + | server_tokens off; | ||
| + | listen 80; | ||
| + | listen 443 ssl http2; | ||
| + | access_log / | ||
| + | # No default.crt certificate found for this vhost, so force nginx to emit a | ||
| + | # TLS error if the client connects via https. | ||
| + | ssl_ciphers aNULL; | ||
| + | set $empty ""; | ||
| + | ssl_certificate data: | ||
| + | ssl_certificate_key data: | ||
| + | if ($https) { | ||
| + | return 444; | ||
| + | } | ||
| + | return 503; | ||
| + | } | ||
| + | # alf.digital/ | ||
| + | upstream alf.digital { | ||
| + | # Container: businesscard_s3 | ||
| + | # | ||
| + | # | ||
| + | # IP address: 172.18.0.3 | ||
| + | # | ||
| + | # | ||
| + | # using port: 8081 | ||
| + | # /!\ WARNING: Virtual port published on host. Clients | ||
| + | # might be able to bypass nginx-proxy and | ||
| + | # access the container' | ||
| + | server 172.18.0.3: | ||
| + | } | ||
| + | server { | ||
| + | server_name alf.digital; | ||
| + | listen 80 ; | ||
| + | access_log / | ||
| + | # Do not HTTPS redirect Let's Encrypt ACME challenge | ||
| + | location ^~ / | ||
| + | auth_basic off; | ||
| + | auth_request off; | ||
| + | allow all; | ||
| + | root / | ||
| + | try_files $uri =404; | ||
| + | break; | ||
| + | } | ||
| + | location / { | ||
| + | return 301 https:// | ||
| + | } | ||
| + | } | ||
| + | server { | ||
| + | server_name alf.digital; | ||
| + | access_log / | ||
| + | listen 443 ssl http2 ; | ||
| + | ssl_session_timeout 5m; | ||
| + | ssl_session_cache shared: | ||
| + | ssl_session_tickets off; | ||
| + | ssl_certificate / | ||
| + | ssl_certificate_key / | ||
| + | set $sts_header ""; | ||
| + | if ($https) { | ||
| + | set $sts_header " | ||
| + | } | ||
| + | add_header Strict-Transport-Security $sts_header always; | ||
| + | location / { | ||
| + | proxy_pass http:// | ||
| + | set $upstream_keepalive false; | ||
| + | } | ||
| + | } | ||
| + | # card.alf.digital/ | ||
| + | upstream card.alf.digital { | ||
| + | # Container: businesscard_s3 | ||
| + | # | ||
| + | # | ||
| + | # IP address: 172.18.0.3 | ||
| + | # | ||
| + | # | ||
| + | # using port: 8081 | ||
| + | # /!\ WARNING: Virtual port published on host. Clients | ||
| + | # might be able to bypass nginx-proxy and | ||
| + | # access the container' | ||
| + | server 172.18.0.3: | ||
| + | } | ||
| + | server { | ||
| + | server_name card.alf.digital; | ||
| + | listen 80 ; | ||
| + | access_log / | ||
| + | # Do not HTTPS redirect Let's Encrypt ACME challenge | ||
| + | location ^~ / | ||
| + | auth_basic off; | ||
| + | auth_request off; | ||
| + | allow all; | ||
| + | root / | ||
| + | try_files $uri =404; | ||
| + | break; | ||
| + | } | ||
| + | location / { | ||
| + | return 301 https:// | ||
| + | } | ||
| + | } | ||
| + | server { | ||
| + | server_name card.alf.digital; | ||
| + | access_log / | ||
| + | listen 443 ssl http2 ; | ||
| + | ssl_session_timeout 5m; | ||
| + | ssl_session_cache shared: | ||
| + | ssl_session_tickets off; | ||
| + | ssl_certificate / | ||
| + | ssl_certificate_key / | ||
| + | set $sts_header ""; | ||
| + | if ($https) { | ||
| + | set $sts_header " | ||
| + | } | ||
| + | add_header Strict-Transport-Security $sts_header always; | ||
| + | location / { | ||
| + | proxy_pass http:// | ||
| + | set $upstream_keepalive false; | ||
| + | } | ||
| + | } | ||
| + | # wiki.alf.digital/ | ||
| + | upstream wiki.alf.digital { | ||
| + | # Container: wiki_localhost | ||
| + | # | ||
| + | # | ||
| + | # IP address: 172.18.0.2 | ||
| + | # | ||
| + | # | ||
| + | # using port: 8080 | ||
| + | # /!\ WARNING: Virtual port published on host. Clients | ||
| + | # might be able to bypass nginx-proxy and | ||
| + | # access the container' | ||
| + | server 172.18.0.2: | ||
| + | } | ||
| + | server { | ||
| + | server_name wiki.alf.digital; | ||
| + | listen 80 ; | ||
| + | access_log / | ||
| + | # Do not HTTPS redirect Let's Encrypt ACME challenge | ||
| + | location ^~ / | ||
| + | auth_basic off; | ||
| + | auth_request off; | ||
| + | allow all; | ||
| + | root / | ||
| + | try_files $uri =404; | ||
| + | break; | ||
| + | } | ||
| + | location / { | ||
| + | return 301 https:// | ||
| + | } | ||
| + | } | ||
| + | server { | ||
| + | server_name wiki.alf.digital; | ||
| + | access_log / | ||
| + | listen 443 ssl http2 ; | ||
| + | ssl_session_timeout 5m; | ||
| + | ssl_session_cache shared: | ||
| + | ssl_session_tickets off; | ||
| + | ssl_certificate / | ||
| + | ssl_certificate_key / | ||
| + | set $sts_header ""; | ||
| + | if ($https) { | ||
| + | set $sts_header " | ||
| + | } | ||
| + | add_header Strict-Transport-Security $sts_header always; | ||
| + | location / { | ||
| + | proxy_pass http:// | ||
| + | set $upstream_keepalive false; | ||
| + | } | ||
| + | } | ||
| + | # www.alf.digital/ | ||
| + | upstream www.alf.digital { | ||
| + | # Container: businesscard_s3 | ||
| + | # | ||
| + | # | ||
| + | # IP address: 172.18.0.3 | ||
| + | # | ||
| + | # | ||
| + | # using port: 8081 | ||
| + | # /!\ WARNING: Virtual port published on host. Clients | ||
| + | # might be able to bypass nginx-proxy and | ||
| + | # access the container' | ||
| + | server 172.18.0.3: | ||
| + | } | ||
| + | server { | ||
| + | server_name www.alf.digital; | ||
| + | listen 80 ; | ||
| + | access_log / | ||
| + | # Do not HTTPS redirect Let's Encrypt ACME challenge | ||
| + | location ^~ / | ||
| + | auth_basic off; | ||
| + | auth_request off; | ||
| + | allow all; | ||
| + | root / | ||
| + | try_files $uri =404; | ||
| + | break; | ||
| + | } | ||
| + | location / { | ||
| + | return 301 https:// | ||
| + | } | ||
| + | } | ||
| + | server { | ||
| + | server_name www.alf.digital; | ||
| + | access_log / | ||
| + | listen 443 ssl http2 ; | ||
| + | ssl_session_timeout 5m; | ||
| + | ssl_session_cache shared: | ||
| + | ssl_session_tickets off; | ||
| + | ssl_certificate / | ||
| + | ssl_certificate_key / | ||
| + | set $sts_header ""; | ||
| + | if ($https) { | ||
| + | set $sts_header " | ||
| + | } | ||
| + | add_header Strict-Transport-Security $sts_header always; | ||
| + | location / { | ||
| + | proxy_pass http:// | ||
| + | set $upstream_keepalive false; | ||
| + | } | ||
| + | } | ||
| + | </ | ||
