Response
stringlengths
8
2k
Instruction
stringlengths
18
2k
Prompt
stringlengths
14
160
I'd look into something likeSupervisor.Very useful tutorial can be found herehttps://www.codingforentrepreneurs.com/blog/hello-linux-setup-gunicorn-and-supervisor/
I want to make a Flask+Nginx+Gunicorn deployment. I have Nginx setup and running and I run gunicorn as described in the docs:gunicorn app:appBut when I logout of the server the gunicorn process exits? What is the correct way to make sure it stay running for Nginx to connect to, and restarts if it crashes?
What is the correct way to leave gunicorn running?
Why is something like that useful? At first look I wasn't sure if it could be done. But it presented an interesting question.You might try putting a redirect statement in your config file and restarting your server. Two possibilities might happen:The server will issue the redirect - what you seem to want.The server will first do the https exchange, and THEN issue the redirect, in which case, what's the point?Will add more if I come up with something more concrete.UPDATE:(couple of hours later)You could try this. You need to put this in yournginx.conffile -server { listen 443; server_name _ *; rewrite ^(.*) http://$host$1 permanent; }Sends a permanent redirect to the client. I am assuming you are using port 443 (default) for https.server { listen 80; server_name _ *; ... }Add this so that your normal http requests on port 80 are undisturbed.UPDATE:18th Dec 2016-server_name _should be used instead ofserver_name _ *in nginx versions > 0.6.25 (thanks to @Luca Steeb)
Is there a way to redirect HTTPS requests to HTTP by adding a rule in the domain's vhost file?
How do I redirect HTTPS to HTTP on NGINX?
This behaviour is documented athttps://docs.docker.com/compose/extends/#adding-and-overriding-configurationFor the multi-value optionsports,expose,external_links,dns,dns_search, andtmpfs, Compose concatenates both sets of valuesSince theportswill be the concatenation of the ports in all your compose files, I would suggest creating a newdocker-compose.dev.ymlfile which contains your development port mappings, removing them from the basedocker-compose.ymlfile.AsNikson says, you can name thisdocker-compose.override.ymlto apply your development configuration automatically without chaining the docker-compose files.docker-compose.override.ymlwill not be applied if you manually specify another override file (e.g.docker-compose -f docker-compose.yml -f docker-compose.prod.yml)
My docker compose configs look like this:docker-compose.ymlversion: '3.5' services: nginx: ports: - 8080:8080docker-compose.prod.ymlversion: '3.5' services: nginx: ports: - 80:80Now, when I run command:docker-compose -f docker-compose.yml -f docker-compose.prod.yml upthe nginx exposes on host machine two ports:8000and80, because it merges ports properties:version: '3.5' services: nginx: ports: - 8080:8080 - 80:80Is there a way to override it? I want to expose only port80.
docker compose override a ports property instead of merging it
Uploading files is actually possible with AJAX these days. Yes, AJAX, not some crappy AJAX wannabes like swf or java.This example might help you out:https://webblocks.nl/tests/ajax/file-drag-drop.html(It also includes the drag/drop interface but that's easily ignored.)Basically what it comes down to is this: (demo:http://jsfiddle.net/rudiedirkx/jzxmro8r/)So basically what it comes down to is this =)xhr.send(file);Wherefileis typeofBlob:http://www.w3.org/TR/FileAPI/Another (better IMO) way is to useFormData. This allows you to 1) name a file, like in a form and 2) send other stuff (files too), like in a form.var fd = new FormData; fd.append('photo1', file); fd.append('photo2', file2); fd.append('other_data', 'foo bar'); xhr.send(fd);FormDatamakes the server code cleaner and more backward compatible (since the request now has the exact same format as normal forms).All of it is not experimental, but very modern. Chrome 8+ and Firefox 4+ know what to do, but I don't know about any others.This is how I handled the request (1 image per request) in PHP:if ( isset($_FILES['file']) ) { $filename = basename($_FILES['file']['name']); $error = true; // Only upload if on my home win dev machine if ( isset($_SERVER['WINDIR']) ) { $path = 'uploads/'.$filename; $error = !move_uploaded_file($_FILES['file']['tmp_name'], $path); } $rsp = array( 'error' => $error, // Used in JS 'filename' => $filename, 'filepath' => '/tests/uploads/' . $filename, // Web accessible ); echo json_encode($rsp); exit; }
It seems like I have not clearly communicated my problem. I need to send a file (using AJAX) and I need to get the upload progress of the file using theNginx HttpUploadProgressModule. I need a good solution to this problem. I have tried with the jquery.uploadprogress plugin, but I am finding myself having to rewrite much of it to get it to work in all browsers and to send the file using AJAX.All I need is the code to do this and it needs to work in all major browsers (Chrome, Safari, FireFox, and IE). It would be even better If I could get a solution that will handle multiple file uploads.I am using thejquery.uploadprogress pluginto get the upload progress of a file from the NginxHttpUploadProgressModule. This is inside an iframe for a facebook application. It works in firefox, but it fails in chrome/safari.When I open the console I get this.Uncaught ReferenceError: progressFrame is not defined jquery.uploadprogress.js:80Any idea how I would fix that?I would like to also send the file using AJAX when it is completed. How would I implement that?EDIT:I need this soon and it is important so I am going to put a 100 point bounty on this question. The first person to answer it will receive the 100 points.EDIT 2:Jake33 helped me solve the first problem. First person to leave a response with how to send the file with ajax too will receive the 100 points.
jQuery Upload Progress and AJAX file upload
To answer your question:in php-fpm.d/www.conf file:set the access.log entry:access.log = /var/log/$pool.access.logrestart php-fpm service.try to access your pagecat /var/log/www.access.log, you will see access logs like:- - 10/Nov/2016:19:02:11 +0000 "GET /app.php" 404 - - 10/Nov/2016:19:02:37 +0000 "GET /app.php" 404To resolve "Primary script unknown" problem:if you see "GET /" without a correct php file name, then it's your nginx conf problem.if you see "GET /app.php" with 404, it means nginx is correctly passing the script file name but php-fpm failed to access this file (user "php-fpm:php-fpm" don't have access to your file, which trapped me for 3 hours)Hope my answer helps.
SO has many articles mentioning this error code:FastCGI sent in stderr: "Primary script unknown" while reading response header from upstream...That probably means that this error message is more or less useless.The message is telling us that the FastCGI handler doesn't like whatever it was sent for some reason. The problem is that sometimes we have no idea what the reason is.So I'm re-stating the question -- How do wedebugthis error code?Consider the situation where we have a very simple site, with just the phpinfo.php file. Additionally, there is a very simple nginx config, as follows:server { server_name testsite.local; root /var/local/mysite/; location / { index index.html index.htm index.php; } location ~ \.php$ { include /etc/nginx/fastcgi_params; fastcgi_pass fastcgi_backend; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; } }How can we see output/log exactly what fastcgi_params got sent to the script?How can we see the actual error message?In my case, I'm using php-fpm. It has no info in the log about this error. The logs do not append any rows for this error. Is there a verbose mode for php-fpm?/var/log/php-fpm/error.log /var/log/php-fpm/www-error.logI've tried to set this in the php-fpm.conf filelog_level = noticeand this in the php-fpm.d/www.conf file:catch_workers_output = yes
How to debug "FastCGI sent in stderr: Primary script unknown while reading response header from upstream" and find the actual error message?
The documentation says:The default_server parameter, if present, will cause the server to become the default server for the specified address:port pair.It's also obvious, there can be only onedefaultserver.And it is also says:A listen directive can have several additional parameters specific to socket-related system calls. They can be specified in any listen directive, but only once for the given address:port pair.So, you should removedefaultanddeferredfrom one of thelisten 80directives. And same applies toipv6only=ondirective as well.
I have a Rails app up and running on my server and now I'd like to add another one.I want Nginx to check what the request is for and split traffic based on domain nameBoth sites have their own nginx.conf symlinked into sites-enabled, but I get an error starting nginxStarting nginx: nginx: [emerg] duplicate listen options for 0.0.0.0:80 in /etc/nginx/sites-enabled/bubbles:6They are both listening on 80 but for different things.Site #1upstream blog_unicorn { server unix:/tmp/unicorn.blog.sock fail_timeout=0; } server { listen 80 default deferred; server_name walrus.com www.walrus.com; root /home/deployer/apps/blog/current/public; location ^~ /assets/ { gzip_static on; expires max; add_header Cache-Control public; } try_files $uri/index.html $uri @blog_unicorn; location @blog_unicorn { proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_set_header Host $http_host; proxy_redirect off; proxy_pass http://blog_unicorn; } error_page 500 502 503 504 /500.html; client_max_body_size 4G; keepalive_timeout 10; }Site two:upstream bubbles_unicorn { server unix:/tmp/unicorn.bubbles.sock fail_timeout=0; } server { listen 80 default deferred; server_name bubbles.com www.bubbles.com; root /home/deployer/apps/bubbles/current/public; location ^~ /assets/ { gzip_static on; expires max; add_header Cache-Control public; } try_files $uri/index.html $uri @bubbles_unicorn; location @bubbles_unicorn { proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_set_header Host $http_host; proxy_redirect off; proxy_pass http://bubbles_unicorn; } error_page 500 502 503 504 /500.html; client_max_body_size 4G; keepalive_timeout 10; }
Serving two sites from one server with Nginx
According tonginxdocumentationthere is no syntax for NOT matching a regular expression. Instead, match the target regular expression and assign an empty block, then use location / to match anything elseSo you could define something likelocation ~ (dir1|file2\.php) { # empty } location / { rewrite ^/(.*) http://example.com/$1 permanent; }
How do I set alocationcondition in Nginx that responds to anything that isn't equal to the listed locations?I tried:location !~/(dir1|file2\.php) { rewrite ^/(.*) http://example.com/$1 permanent; }But it doesn't trigger the redirect. It simply handles the requested URI using the rules in the rest of the server configuration.
Nginx location "not equal to" regex
Not quite enough info to say definitively, but based on the config you've provided, it looks like you have loop. You're proxying the requests to localhost:80, but NGINX is most likely listening on port 80. So, NGINX is connecting to itself over and over, hence the errors about too many open files.Also, Kibana doesn't have any server-side code, so proxy_pass isn't appropriate here. Something like the following should be enough:root /var/www/ location /kibana-3.1.2 { try_files $uri $uri/ =404; }With that being said, if you intend for this to be accessible from the public internet, you should protect it with a password and you should use proxy_pass in front of elasticsearch to control what requests can be made to it. But that's a different story :)
I am trying accesskibanaapplication deployed innginx,but getting belowURL :-http://127.0.0.1/kibana-3.1.22015/02/01 23:05:05 [alert] 3919#0: *766 768 worker_connections are not enough while connecting to upstream, client: 127.0.0.1, server: , request: "GET /kibana-3.1.2 HTTP/1.0", upstream: "http://127.0.0.1:80/kibana-3.1.2", host: "127.0.0.1"Kibana is deployed at/var/www/kibana-3.1.2I have tried to increase theworker_connections,but still no luck,getting below in this case.2015/02/01 23:02:27 [alert] 3802#0: accept4() failed (24: Too many open files) 2015/02/01 23:02:27 [alert] 3802#0: accept4() failed (24: Too many open files) 2015/02/01 23:02:27 [alert] 3802#0: accept4() failed (24: Too many open files) 2015/02/01 23:02:27 [alert] 3802#0: accept4() failed (24: Too many open files) 2015/02/01 23:02:27 [alert] 3802#0: accept4() failed (24: Too many open files)nginx.conf :-user www-data; worker_processes 4; pid /var/run/nginx.pid; events { worker_connections 768; # multi_accept on; }And below in the location directive.location /kibana-3.1.2{ proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $remote_addr; proxy_set_header Host $host; proxy_pass http://127.0.0.1; add_header Access-Control-Allow-Origin *; add_header Access-Control-Allow-Headers *; }
worker_connections are not enough
Your rails_env production don't have required set up,probably missing secret_key_base.Open/etc/nginx/sites-available/defaultand change the rails_env to development:rails_env production; to rails_env development;If the app is loading it's not a passenger issue.Production Solution:Enter your app rootrun:rake secretcopy the outputgo to/yourapp/config/secrets.ymlset the productionsecret_key_baseRestart the passenger app :touch /yourapp/tmp/restart.txt
I tried to deploy my rails app on nginx and ubuntu via capistrano like the tutorial on the pagehttps://gorails.com/deploy/ubuntu/14.04. but at the end i get an error message:Incomplete response received from applicationin my browser. this is probably an error from passenger, but how can i figure out what to do?
"Incomplete response received from application" from nginx / passenger
I think you may be confused, Flask is not aweb server, it is a framework and needs some sort of web server, such as Gunicorn, Nginx or Apache, to accept HTTP requests which it will then operate on. The reason why people run Nginx and Gunicorn together is that in addition to being a web server, Nginx can also proxy connections to Gunicorn which brings certain performance benefits, here is a pretty good answer that elaborates on those benefits:https://serverfault.com/questions/220046/why-is-setting-nginx-as-a-reverse-proxy-a-good-ideaEDIT:Added link containing information about performance benefits of running Nginx as a proxy.
This question already has answers here:Are a WSGI server and HTTP server required to serve a Flask app?(3 answers)Closed5 years ago.I see people are running setups like Nginx + Gunicorn + Flask.Can someone explain what is the benefit of having Gunicorn in front of Flask? Why not just run Flask alone? Doesn't it consume more resources having Gunicorn + Flask running? Is Gunicorn able to reboot the Flask instance when it fails to respond?What's also the purpose of having nginx on top of gunicorn? Isn't gunicorn enough? Again, more resources being spent?
What benefit is added by using Gunicorn + Nginx + Flask? [duplicate]
It is for the IPv6 configsfrom the nginxdocsIPv6 addresses (0.7.36) are specified in square brackets: listen [::]:8000; listen [::1];
I was looking at my nginx config file I noticed two this.server { listen 80 default_server; listen [::]:80 default_server; index index.html; }I understand this partlisten 80 default_server;it tells nginx to listen on port 80 and set that as the "default_server" but I do not understand the second line.listen [::]:80 default_server;It appears I am setting the default server again on port 80 but I do not really understand the[::]part of it at all.Can someone explain to me what this configuration does?
What does [::] mean in my nginx config file
Update:Thanks to @Putnik for pointing out an easier way (but I prefer only listing sites-enabled):grep server_name /etc/nginx/sites-enabled/* -RiIOld Post:Try something like this:find /etc/nginx/sites-enabled/ -type f -print0 | xargs -0 egrep '^(\s|\t)*server_name'
Is there a command that will list all vhosts or servers running under nginx on CentOS? I would like to pipe the results to a text file for reporting purposes.I'm looking for something similar to this command that I use for Apache:apachectl -S 2>&1 | grep 'port 80'
How can I list all vhosts in nginx
I had this same problem before. Because Nginx can't do complex conditions or nested if statements, you need to evaluate over 2 different expressions.set a variable to some binary value then enable if either condition is true in 2 different if statements:set $my_var 0; if ($host = 'domain.example') { set $my_var 1; } if ($host = 'domain2.example') { set $my_var 1; } if ($my_var = 1) { rewrite ^/(.*)$ http://www.domain.example/$1 permanent; }
I want to redirect requests on two conditions using Nginx.This doesn't work:if ($host = 'domain.example' || $host = 'domain2.example'){ rewrite ^/(.*)$ http://www.domain.example/$1 permanent; }What is the correct way to do this?
nginx.conf redirect multiple conditions
For nginx/mod_wsgi, ensure you read:http://blog.dscpl.com.au/2009/05/blocking-requests-and-nginx-version-of.htmlBecause of how nginx is an event driven system underneath, it has behavioural characteristics which are detrimental to blocking applications such as is the case with WSGI based applications. Worse case scenario is that with multiprocess nginx configuration, you can see user requests be blocked even though some nginx worker processes may be idle. Apache/mod_wsgi doesn't have this issue as Apache processes will only accept requests when it has the resources to actually handle the request. Apache/mod_wsgi will thus give more predictable and reliable behaviour.
What to use for a medium to large python WSGI application, Apache + mod_wsgi or Nginx + mod_wsgi?Which combination will need more memory and CPU time?Which one is faster?Which is known for being more stable than the other?I am also thinking to use CherryPy's WSGI server but I hear it's not very suitable for a very high-load application, what do you know about this?Note: I didn't use any Python Web Framework, I just wrote the whole thing from scratch.Note': Other suggestions are also welcome.
In production, Apache + mod_wsgi or Nginx + mod_wsgi?
Reloading nginx is safer than restarting because before old process will be terminated, new configuration file is parsed and whole process is aborted if there are any problems with it.On the other hand when you restart nginx you might encounter situation in which nginx will stop, and won't start back again, because of syntax error.Reloading terminates the old process, so any memory leaks should be cleared anyway.
When is it necessary to restart nginx and reload will not suffice?Does it make a difference if an extension likepassengeris used?Should the service be restarted if it consumes too much memory. Any other reasons for restarting Nginx, particularly after a configuration change either in an extension or a Nginx core config?After making a configuration change, one can either restart or reload nginx, via thebinaryitself or the init.d script "/etc/init.d/nginx -h" on Ubuntu. Which method should be preferred?
When to restart and not reload Nginx?
I'd personally use Amazon's own repo.The version provided by the Amazon repo is relatively old (1.12.2at the time of writing). To see what versions the Amazon repo has access to runamazon-linux-extras list | grep nginxIf you'd like a later version, consider EPEL.In regards to the config, your best bet is to explicitly supply the configuration you require to the server.Using the off-the-peg ones are fine to get you up and running. However you run the risk of things changing when Nginx updates. Explicitly supplying your own configuration gives you greater control over what is running.Probably the simplest approach would be to upload the configuration generated bynginxconfig.ioto S3.Then add a script via user data when creating the EC2 instance to download your configuration.https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/user-data.htmlSomething like this...#!/bin/bash # Install Nginx amazon-linux-extras install nginx1.12 # Back up existing config mv /etc/nginx /etc/nginx-backup # Download the configuration from S3 aws s3 cp s3://{my_bucket}/nginxconfig.io-example.com.zip /tmp # Install new configuration unzip /tmp/nginxconfig.io-example.com.zip -d /etc/nginxThe configuration supplied bynginxconfig.iosets up all the sites enabled/available for you.
Closed.This question does not meetStack Overflow guidelines. It is not currently accepting answers.This question does not appear to be abouta specific programming problem, a software algorithm, or software tools primarily used by programmers. If you believe the question would be on-topic onanother Stack Exchange site, you can leave a comment to explain where the question may be able to be answered.Closed3 years ago.Improve this questionI'm new to AWS and trying to understand which version of NGINX I should be installing on my instance. I've found multiple options;ViaEPELas the blog entryAmazon's own (?) version as thisanswerThe 2016 NGINX officialtutorialOn my development environment (Centos VM) I usedsudo yum install nginx. Having tried the EPEL route I don't get the same set up, in particular sites enabled/available is not created as part of the setup. I want to usenginxconfig.iowhich requires those. Which version of NGINX should i use for that?
How to install NGINX on AWS EC2 Linux 2 [closed]
The answer is to place the root dir to the location directives:root /srv/www/ducklington.org/public_html;
How to set index.html for the domain name e.g.https://www.example.com/- leads user to index.html in root directory.I've tried different things like:server { # some configs location = / { index index.html; fastcgi_index index.html; } or location / { index index.html; fastcgi_index index.html; } }Nothing helped me.There are some other configs with location keyword, though I'd commented them either.Other "location" configs in theserver {clause:location ~ .*(css|htc|js|bmp|jp?g|gif|ico|cur|png|swf|htm?|html)$ { access_log off; root $www_root; } location ~ \.php$ { include /etc/nginx/fastcgi_params; index index.html; fastcgi_index index.html; fastcgi_param SCRIPT_FILENAME $www_root$fastcgi_script_name; fastcgi_param QUERY_STRING $query_string; fastcgi_param PATH_INFO $fastcgi_path_info; fastcgi_pass 127.0.0.1:9000; # Директива определяет что ответы FastCGI-сервера с кодом больше или равные 400 # перенаправлять на обработку nginx'у с помощью директивы error_page fastcgi_intercept_errors on; break; } location ~ /\.ht { deny all; }All them were commented and uncommented, but nothing helped.PS Editions were made in /etc/nginx/sites-enabled/domainname.com file.
How to set index.html as root file in Nginx?
You're not forwarding any information about whether this request was an HTTPS-terminated request or not. Normally, in a server, the "ssl on;" directive will set these headers, but you're using a combined block.Rack (and force_ssl) determines SSL by:If the request came in on port 443 (this is likely not being passed back to Unicorn from nginx)If ENV['HTTPS'] == "on"If the X-Forwarded-Proto header == "HTTPS"Seethe force_ssl sourcefor the full story.Since you're using a combined block, you want to use the third form. Try:proxy_set_header X-Forwarded-Proto $scheme;in your server or location blockper the nginx documentation.This will set the header to "http" when you come in on a port 80 request, and set it to "https" when you come in on a 443 request.
I want to have my API controller use SSL, so I added another listen directive to my nginx.confupstream unicorn { server unix:/tmp/unicorn.foo.sock fail_timeout=0; } server { listen 80 default deferred; listen 443 ssl default; ssl_certificate /etc/ssl/certs/foo.crt; ssl_certificate_key /etc/ssl/private/foo.key; server_name foo; root /var/apps/foo/current/public; try_files $uri/system/maintenance.html $uri/index.html $uri @unicorn; location @unicorn { proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_set_header Host $http_host; proxy_redirect off; proxy_pass http://unicorn; } error_page 502 503 /maintenance.html; error_page 500 504 /500.html; keepalive_timeout 5; }which passes the nginx conftest without any problems. I also added aforce_ssldirective to my ApiControllerclass ApiController < ApplicationController force_ssl if Rails.env.production? def auth user = User.authenticate(params[:username], params[:password]) respond_to do |format| format.json do if user user.generate_api_key! unless user.api_key.present? render json: { key: user.api_key } else render json: { error: 401 }, status: 401 end end end end def check user = User.find_by_api_key(params[:api_key]) respond_to do |format| format.json do if user render json: { status: 'ok' } else render json: { status: 'failure' }, status: 401 end end end end endwhich worked just fine when I wasn't using SSL, but now when I try tocurl --LI http://foo/api/auth.json, I get properly redirected tohttps, but then I keep on getting redirected tohttp://foo/api/authending in an infinite redirect loop.My routes simply haveget "api/auth" get "api/check"I'm using Rails 3.2.1 on Ruby 1.9.2 with nginx 0.7.65
Why am I getting infinite redirect loop with force_ssl in my Rails app?
It's similar to setting up the custom 404 pages. Here's what I've got.#site-wide error pages error_page 404 /404.html; error_page 500 502 503 504 /500.html;
Is it possible to serve a custom "Bad Gateway" error page in Nginx?Similar to having custom 404 pages.
Custom Bad Gateway Page with Nginx
The correct usage would be$SOME_IP_from_env, but environment variables set from nginx.conf cannot be used in server, location or http blocks.You can use environment variables if you use theopenresty bundle, which includes Lua.
I have the following scenario: I have an env variable$SOME_IPdefined and want to use it in a nginx block. Referring to thenginx documentationI use theenvdirective in thenginx.conffile like the following:user www-data; worker_processes 4; pid /run/nginx.pid; env SOME_IP;Now I want to use the variable for aproxy_pass. I tried it like the following:location / { proxy_pass http://$SOME_IP:8000; }But I end up with this error message:nginx: [emerg] unknown "some_ip" variable
nginx: use environment variables
go to/etc/nginx/sites-availablethen modify the host file which should listen to a different port (if you didn't change anything here you will find adefaultfile, enter to change it)in the file changelisten: 80to the port you want to listen todon't forget to reload the service:service nginx reload
I want to configure both Apache and nginx to run together on Ubuntu because I want to develop on both nginx and Apache. I have read that I have to edit the configuration on Apache or nginx to make one of them run on another port rather than 80.Which files should I edit in Nginx to make it run through another port?
How can I run both nginx and Apache together on Ubuntu?
What is your nginx pid file location? This is specified in the configuration file, default paths specified compile-time in the config script. You can search for it as such:find / -name nginx.pid 2>/dev/null(must issue while nginx is running)Solution:sudo mkdir -p /usr/local/var/run/ ln -s /current/path/to/pid/file /usr/local/var/run/nginx.pid
I'm usingnginxon OS X 10.8. Freshly installednginxbut can't find a way to restart nginx exceptkill nginx_pidsaykill 64116. Wondering if there are better ways to restartnginx.Found some methods on Google and SO but didn't work:nginx -s restart sudo fuser -k 80/tcp ; sudo /etc/init.d/nginx restartThe error message fornginx -s restartisnginx: [error] open() "/usr/local/var/run/nginx.pid" failed (2: No such file or directory)Sometimes also get this error msg:nginx: invalid option: "-s restart"
How to restart nginx on OS X
You can get your current IP address as shownhere:ifconfig en0 | grep inet | grep -v inet6 | awk '{print $2}'Then you can use the--add-hostflag withdocker run:docker run --add-host localnode:$(ifconfig en0 | grep inet | grep -v inet6 | awk '{print \$2}') ...In yourproxypassuselocalnodeinstead oflocalhost.
I'm trying to use a dockerized version of nginx as a proxy server for my node (ExpressJS) application. Without any configuration to nginx and publishing port 80 for the container, I am able to see the default nginx landing page. So I know that much is working.Now I can mount my sites-enabled directory that contains the configuration forproxy_pass localhost:3000. I have my node application running locally (not in any Docker container) and I can access it via port 3000 (i.e.localhost:3000). However, I would assume that with nginx container running, mapped to port 80, and proxying my localhost:3000, that I would be able to see myverysimple (hello world) application. Instead I receive a 502.Do I need to pass something into docker? Is this likely a nginx configuration error? Here is my nginx configuration:server { listen 0.0.0.0:80; server_name localhost; location / { proxy_pass http://localhost:3000; } }I have tried usingthis questionbut it did not seem to help. That is unless I'm doing something completely wrong.
How do I access a server on localhost with nginx docker container?
Option 1:This will install the latest version of PhpMyAdmin from a shell script I've written. You are welcome to check it outon Github.Run the following command from your code/projects directory:curl -sS https://raw.githubusercontent.com/grrnikos/pma/master/pma.sh | bashOption 2:This will install PhpMyAdmin (not the latest version) from Ubuntu's repositories. Assuming that your projects live in/home/vagrant/Code:sudo apt-get install phpmyadminDonotselect apache2 nor lighttpd when prompted. Just hit tab and enter.sudo ln -s /usr/share/phpmyadmin/ /home/vagrant/code/phpmyadmincd ~/Code && serve phpmyadmin.test /home/vagrant/code/phpmyadminNote: If you encounter issues creating the symbolic link on step 2, try the first option or see Lyndon Watkins' answer below.Final steps:Open the/etc/hostsfile on your main machine and add:127.0.0.1 phpmyadmin.testGo tohttp://phpmyadmin.test:8000
I installed it by runningsudo apt-get install phpymyadminand then runningsudo ln -s /usr/share/phpmyadmin/ /usr/share/nginx/htmlandsudo service nginx restartbut it's not working.Note: I didn't select any of the apache2 or lighttpd options when installing.
How do I set up phpMyAdmin on a Laravel Homestead box?
This is an working config that I currently use in production.http://pastie.org/10870547gzip on; gzip_disable "msie6"; gzip_comp_level 6; gzip_min_length 1100; gzip_buffers 16 8k; gzip_proxied any; gzip_types text/plain text/css text/js text/xml text/javascript application/javascript application/json application/xml application/rss+xml image/svg+xml;This config was tested via tools.pingdom.com.
I need to enable gzip compression on nginx server. As I have observed from firfox firebug NET tools, I have found that html file are gzip compressed. But Not the javascript files and CSS files.I have already checkMime.typesand nginx configuration file/etc/nginx/ngnix.confand not found any issue. still not able to see the css and javascript Gzip Compression. My NGINX.conf entries are as belowgzip on; gzip_disable "msie6"; gzip_vary on; gzip_proxied any; gzip_comp_level 6; gzip_buffers 16 8k; gzip_http_version 1.1; gzip_types text/plain text/css application/json application/x-javascript text/xml application/xml application/xml+rss text/javascript;
Enable GZIP for CSS and JS files on NGINX server for Magento
Add this to yourhttp {}of thenginx.conffile normally located at/etc/nginx/nginx.conf:proxy_buffer_size 128k; proxy_buffers 4 256k; proxy_busy_buffers_size 256k;Then add this to your php location block, this will be located in your vhost file look for the block that begins withlocation ~ .php$ {fastcgi_buffer_size 128k; fastcgi_buffers 4 256k; fastcgi_busy_buffers_size 256k;
I am getting this error from Nginx, but can't seem to figure it out! I am using codeigniter and am using the database for sessions. So I'm wondering how the header can ever be too big. Is there anyway to check what the header is? or potentially see what I can do to fix this error?Let me know if you need me to put up any conf files or whatever and I'll update as you request them2012/12/15 11:51:39 [error] 2007#0: *5778 upstream sent too big header while reading response header from upstream, client: 24.63.77.149, server: jdobres.xxxx.com, request: "POST /main/login HTTP/1.1", upstream: "fastcgi://127.0.0.1:9000", host: "jdobres.xxxxx.com", referrer: "http://jdobres.xxxx.com/"UPDATEI added the following into conf:proxy_buffer_size 512k; proxy_buffers 4 512k; proxy_busy_buffers_size 512k;And now I still get the following:2012/12/16 12:40:27 [error] 31235#0: *929 upstream sent too big header while reading response header from upstream, client: 24.63.77.149, server: jdobres.xxxx.com, request: "POST /main/login HTTP/1.1", upstream: "fastcgi://127.0.0.1:9000", host: "jdobres.xxxx.com", referrer: "http://jdobres.xxxx.com/"
Upstream too big - nginx + codeigniter
From what I've researched, if you append your /etc/nginx/conf.d/domain.tld.conf file to include:location / { try_files $uri $uri.html $uri/ @extensionless-php; index index.html index.htm index.php; } location ~ \.php$ { try_files $uri =404; } location @extensionless-php { rewrite ^(.*)$ $1.php last; }Then restart nginx and give it a go. Hopefully this will help you! More information can be found (where I found it)here @ tweaktalk.net
I want my nginx make display all url's clean.http://www.mydomain.com/indexhtml.htmlashttp://www.mydomain.com/indexhtmlhttp://www.mydomain.com/indexphp.phpashttp://www.mydomain.com/indexphpWith some research I've made the first case to work. It`s done by following configuration:location / { root html; index index.html index.htm index.php; try_files $uri.html $uri/ =404; }It works for indexhtml.html displaying as indexhtml, but nothing happens with .php. If I change $uri.html to $uri.php, it works neither for .html, neither .php. I`ve tried to put something similar in php location but without any success.Any advices?
How to remove both .php and .html extensions from url using NGINX?
Fundamentally you hadn't declare location which is what nginx uses to bind URL with resources.server { listen 80; server_name localhost; access_log logs/localhost.access.log main; location / { root /var/www/board/public; index index.html index.htm index.php; } }
I just installed nginx and php fastcgi about an hour ago, and after reading examples of a quick starting configuration, and the nginx documentation etc, I just cant get it to work.No matter what I change or try, I always only get the "Welcome to Nginx!" screen on "localhost/..." - I cant even call a simple index.htmlMy config:(the stuff in the comments is what I tried out)// default nginx stuff (unchanged) server { #listen 80 default_server; #listen 80 default; listen 80; #server_name localhost; #server_name _; #access_log /var/log/nginx/board.access_log; #error_log /var/log/nginx/board.error_log; #root /var/www/board; #root /var/www/board/public/; root /var/www/board/public; #index index.html; index index.html index.htm index.php; }If I understand it right, this should be the easiest setup, right? just definelisten 80;andindex index.html;but I just cant get it to workThe file /var/www/board/public/index.html exists and has contentBefore I waste 2 more hours trying out something, can someone of you give it a quick watch and tell me what I'm doing wrong? Thanks.
correct configuration for nginx to localhost?
TCP_DEFER_ACCEPT can help boost performance by reducing the amount of preliminary formalities that happen between the server and client.You can read more about itHERE.
I've seen example NGINX configurations with the "deferred" option added to the listen directiveserver { listen 80 default deferred; ... }I can't work out what it does (and whether or not I should use it) and the documentation doesn't make too much sense to medeferred -- indicates to use that postponed accept(2) on Linux with the aid of option TCP_DEFER_ACCEPTCan anyone explain what this option is for?
What does the deferred option mean in NGINXs listen directive?
Nginx uses theReactorpattern. Basically, it's single-threaded (but can fork several processes to utilize multiple cores). The main event loop waits for the OS to signal a readiness event - e.g. that data is available to read from a socket, at which point it is read into a buffer and processed. The single thread can very efficiently serve tens of thousands of simultaneous connections (the thread-per-connection model would fail at this because of the huge context-switching overhead, as well as the large memory consumption, as each thread needs its own stack).
I understand thread driven that Apache uses: every connection opens up a thread and when the response is sent, the thread is closed, releasing the resources for other threads).But I don't get the event driven design that Nginx uses. I've read some basics about event driven design .. but I don't understand how this is used by nginx to handle web requests.Where can i read and understand how Nginx is handling the connections in an event driven way so I get why it's better, rather than just accepting that event-based design is better than thread-driven design.
How does Nginx handle HTTP requests?
You use the error_page property in the nginxconfig.For example, if you intend to set the 404 error page to/404.html, useerror_page 404 /404.html;Setting the 500 error page to/500.htmlis just as easy as:error_page 500 /500.html;
Nginx+PHP (on fastCGI) works great for me. When I enter a path to a PHP file which doesn't exist, instead of getting the default 404 error page (which comes for any invalid .html file), I simply get a "No input file specified.".How can I customize this 404 error page?
Nginx - Customizing 404 page
As of now, the official nginx image uses this to run nginx (seethe Dockerfile):CMD ["nginx", "-g", "daemon off;"]In my case, this was enough to get it to start properly. There are tutorials online suggesting more awkward ways of accomplishing this but the above seems quite clean.
I have tried following some tutorials and documentation on dockerizing my web server, but I am having trouble getting the service to run via the docker run command.This is my Dockerfile:FROM ubuntu:trusty #Update and install stuff RUN apt-get update RUN apt-get install -y python-software-properties aptitude screen htop nano nmap nginx #Add files ADD src/main/resources/ /usr/share/nginx/html EXPOSE 80 CMD service nginx startI create my image:docker build -t myImage .And when I run it:docker run -p 81:80 myImageit seems to just stop:docker ps -a CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 90e54a254efa pms-gui:latest /bin/sh -c service n 3 seconds ago Exit 0 prickly_bohrI would expect this to be running with port 81->80 but it is not. Runningdocker start 90edoes not seem to do anything.I also tried entering it directlydocker run -t -i -p 81:80 myImage /bin/bashand from here I can start the serviceservice nginx startand from another tab I can see it is working as intended (also in my browser):CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 408237a5e10b myImage:latest /bin/bash 12 seconds ago Up 11 seconds 0.0.0.0:81->80/tcp mad_turingSo I assume it is something I am doing wrong with my Dockerfile? Could anyone help me out with this, I am quite new to Docker. Thank you!SOLUTION:Based on the answer from Ivant I found another way to start nginx in the foreground. My Dockerfile CMD now looks like:CMD /usr/sbin/nginx -g "daemon off;"
Dockerized nginx is not starting
I've recently stumbled upon this need myself and have found that in order to use variables in a proxy_pass destination you need to set a resolver as your error.log would most probably contain something likeno resolver defined to resolve ...The solution in my case was to setup the following using a local DNS for DNS resolution:location ~ /proxy/(.*) { resolver 127.0.0.1 [::1]; proxy_pass http://$1; }In your case this should work:location /proxy { resolver 127.0.0.1 [::1]; set $target http://proxytarget.example.com; proxy_pass $target; }For resolver 127.0.0.1 to work, you need to install bind9 locally. For Debian/Ubuntu:sudo apt-get install bind9More information on nginx and dynamicproxy_passing here:http://www.nginx-discovery.com/2011/05/day-51-proxypass-and-resolver.htmlEdit: Replaced the previous public DNS with a local one for securityissues.
I am trying to proxy a request to different targets depending on an environment variable. My approach was to put the target url into the custom variable $target and give this to proxy_pass.But using a variable with proxy_pass doesn't seem to work. This simple config leads to a "502 Bad Gateway" response from nginx.server { listen 8080; server_name myhost.example.com; access_log /var/log/nginx/myhost.access.log; location /proxy { set $target http://proxytarget.example.com; proxy_pass $target; } }The same config without the variable works:server { listen 8080; server_name myhost.example.com; access_log /var/log/nginx/myhost.access.log; location /proxy { proxy_pass http://proxytarget.example.com; } }Is it really not possible to use proxy_pass this way or am I just doing something wrong?
Dynamic proxy_pass to $var with nginx 1.0
http { server { location ~ /\.git { deny all; } } }Thislocationdirective will deny access to any.gitdirectory in any subdirectory.Note:This location block must be before your main location block, so that it can be evaluated first.
Now that I have nginx setup I need to be able to hide my.gitdirectories. What kind of rewrite would I need to stop prying eyes? And where in theserver {}orhttp {}block would it go?
How do you hide .git project directories?
The problem is that nginx doesn't know what to do with/signin. You need to change your nginx config (usually in/etc/nginx/conf.d/) to serve yourindex.htmlregardless of the route. Here is a sample nginx config that might help:server { listen 80 default_server; server_name /var/www/example.com; root /var/www/example.com; index index.html index.htm; location ~* \.(?:manifest|appcache|html?|xml|json)$ { expires -1; # access_log logs/static.log; # I don't usually include a static log } location ~* \.(?:css|js)$ { try_files $uri =404; expires 1y; access_log off; add_header Cache-Control "public"; } # Any route containing a file extension (e.g. /devicesfile.js) location ~ ^.+\..+$ { try_files $uri =404; } # Any route that doesn't have a file extension (e.g. /devices) location / { try_files $uri $uri/ /index.html; } }
I am using React Router for routing for a multi-page website. When trying to go to a sub page directlyhttps://test0809.herokuapp.com/signinyou'd get a "404 Not Found -nginx" error (To be able to see this problem you might need to go to this link in Incognito mode so there's no cache). All the links work fine if you go from the home page:test0809.herokuapp.com/. I was using BrowserRouter and was able to eliminate the "404 not found" error by changing BrowserRouter to HashRouter, which gives all my urls a "#" sign. Besides all the problems with having a "#" in your urls, the biggest issue with it is that I need to implement LinkedIn Auth in my website, and LinkedIn OAuth 2.0 does not allow redirect URLs to contain #.LinedIn OAuth 2.0 error screen grabimport React, { Component } from 'react' import { BrowserRouter as Router, Route, Link } from 'react-router-dom' import LinkedIn from 'react-linkedin-login' const Home = () => Home const About = () => About class Signin extends Component { callbackLinkedIn = code => { console.log(1, code) } render() { return ( Signin ) } } const BasicExample = () => Home About Signin export default BasicExampleAny suggestions on the workarounds?Background: I started the project with create-react-app. GitHub repo:/debelopumento/test0809
React Router BrowserRouter leads to "404 Not Found - nginx " error when going to subpage directly without through a home-page click
just to add--generate-nameat the end ofhelmcommand
How to fixError: must either provide a name or specify --generate-namein HelmCreated sample helm chart name as mychart and written the deployment.yaml, service.yaml, ingress.yaml with nginx service. After that running the command like $ helm install mychartservice.yamlapiVersion: v1 kind: Service metadata: name: nginx spec: ports: - name: main port: 80 protocol: TCP targetPort: 80 selector: app: nginxdeployment.yamlapiVersion: extensions/v1beta2 kind: Deployment metadata: name: nginx spec: replicas: 3 template: metadata: labels: app: nginx spec: containers: - name: nginx image: nginx:1.13 ports: containerPort: 80ingress.yamlapiVersion: extensions/v1beta1 kind: Ingress metadata: name: nginx annotations: http.port: "443" spec: backend: serviceName: nginx servicePort: 80Expected output: .....status: DEPLOYED
"How to fix 'Error: must either provide a name or specify --generate-name' in Helm"
Unlike Apache, all modules, including the 3rd party modules, are going to be compiled into nginx. So every time you want to add a new module, you have to recompile nginx.So yes, you have to install it as per the document. There is no much value of keeping 2 nginx runtimes on the same server any way. So you may also want to remove the previous nginx.
I have installed Nginx in our redhat machine using rpm. Now we want to add nginx-rtmp module, but inorder to add new module as per the document i need to build it by downloading the tar ball. Does it mean that i have to remove the rpm and install it as per the document.Ref:https://github.com/arut/nginx-rtmp-module/wiki/Getting-started-with-nginx-rtmp./configure --add-module=/usr/build/nginx-rtmp-module make make install
How to configure additional modules to nginx after installation?
As mentioned in theNGiNX documentation,upstreamis supposed to be defined in anhttpcontext.As mentioned innginxunkown directive “upstream”:When that file is included normally bynginx.conf, it is included already inside thehttpcontext:http { include /etc/nginx/sites-enabled/*; }You either need to use-c /etc/nginx/nginx.confor make a small wrapper like the above block andnginx -cit.In case of Docker, you can see different options withabevoelker/docker-nginx:docker run -v /tmp/foo:/foo abevoelker/nginx nginx -c /foo/nginx.confFor a defaultnginx.conf,check yourCMD:CMD ["nginx", "-c", "/data/conf/nginx.conf"]
I have a Dockerfile and custom Nginx configuration file (in the same directory with Dockerfile) as follows:Dockerfile:FROM nginx COPY nginx.conf /etc/nginx/nginx.confnginx.conffile:upstream myapp1 { least_conn; server http://example.com:81; server http://example.com:82; server http://example.com:83; } server { listen 80; location / { proxy_pass http://myapp1; proxy_http_version 1.1; proxy_set_header Upgrade $http_upgrade; proxy_set_header Connection 'upgrade'; proxy_set_header Host $host; proxy_cache_bypass $http_upgrade; } }I run these two commands:docker --tls build -t nginx-image . docker --tls run -d -p 80:80 --name nginx nginx-imageThen I checked out all running containers but it didn't show up. When I searched Nginx container's log, I found this error message:[emerg] 1#1: unknown directive "upstream" in /etc/nginx/nginx.conf:1 Nginx: [emerg] unknown directive "upstream" in/etc/nginx/nginx.conf:What am I missing?
How to run Nginx docker container with custom config?
It seems that under pressure, nginx tried to pullangular.jsfrom its cache and couldn't due to permission issues. Here's what solved this issue:root@amac-2:/usr/local/var/run/nginx $ chown -R _www:admin proxy_temp_www:adminmight be different in your case, depending which user owns the nginx process. See more information on ServerFault:https://serverfault.com/questions/534497/why-do-nginx-process-run-with-user-nobody
I'm getting the following error on my chrome console:GET http://localhost/grunt/vendor/angular/angular.js net::ERR_CONTENT_LENGTH_MISMATCHThis only happens when a simultaneous requests are shot towards nginx e.g. when the browsers cache is empty and the whole app loads. Loading the resource above as a single requests succeeds.Here are the headers to this requests, copied from Chrome:Remote Address:127.0.0.1:80 Request URL:http://localhost/grunt/vendor/angular/angular.js Request Method:GET Status Code:200 OK Request Headersview source Accept:*/* Accept-Encoding:gzip,deflate,sdch Accept-Language:en-US,en;q=0.8,de;q=0.6,pl;q=0.4,es;q=0.2,he;q=0.2,gl;q=0.2 Cache-Control:no-cache Connection:keep-alive Cookie:gs_u_GSN-265185-D=1783247335:2567:5000:1377697930719 Host:localhost Pragma:no-cache Referer:http://localhost/grunt/ User-Agent:Mozilla/5.0 (Macintosh; Intel Mac OS X 10_9_4) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/37.0.2062.122 Safari/537.36 Response Headersview source Accept-Ranges:bytes Cache-Control:public, max-age=0 Connection:keep-alive Content-Length:873444 Content-Type:application/javascript Date:Tue, 23 Sep 2014 11:08:19 GMT ETag:"873444-1411465226000" Last-Modified:Tue, 23 Sep 2014 09:40:26 GMT Server:nginx/1.6.0the real size of the file:$ ll vendor/angular/angular.js -rw-rw-r-- 1 xxxx staff 873444 Aug 30 07:21 vendor/angular/angular.jsAs you can seeContent-Lengthand the real size of the file are the same, so that's weirdAnd the nginx configuration to this proxy:location /grunt/ { proxy_pass http://localhost:9000/; }Any ideas?ThanksEDIT: found more info on the error log:2014/09/23 13:08:19 [crit] 15435#0: *8 open() "/usr/local/var/run/nginx/proxy_temp/1/00/0000000001" failed (13: Permission denied) while reading upstream, client: 127.0.0.1, server: localhost, request: "GET /grunt/vendor/angular/angular.js HTTP/1.1", upstream: "http://127.0.0.1:9000/vendor/angular/angular.js", host: "localhost", referrer: "http://localhost/grunt/"
ERR_CONTENT_LENGTH_MISMATCH on nginx and proxy on Chrome when loading large files
location = /abc {}matches the exact uri/abclocation ~ /abcis a regex match on the uri, meaning any uri containing/abc, you probably want:location ~ ^/abcfor the uri begining with/abcinstead
What is the difference between:location = /abc {}andlocaton ~ /abc {}
Nginx location matches
worker_connections is the number of simultaneous connections; so they are simply stating how to calculate, for example:you are only running 1 process with 512 connections, you will only be able to serve 512 clients.If 2 processes with 512 connections each, you will be able to handle 2x512=1024 clients.The number of connections is limited by the maximum number of open files (RLIMIT_NOFILE) on your systemnginxhas a better, updated description of worker connections.fyi, the wiki section is considered obsolete (dont ask), now only the main nginx.org/en/docs are preferred...
Please help me understand whatworker_processesandworker_connectionsare in Nginx and what is the relation between them. I have looked underNginx directivesit says:worker_processesA worker process is a single-threaded process.If Nginx is doing CPU-intensive work such as SSL or gzipping and you have 2 or more CPUs/cores, then you may set worker_processes to be equal to the number of CPUs or cores.If you are serving a lot of static files and the total size of the files is bigger than the available memory, then you may increase worker_processes to fully utilize disk bandwidth.worker_connectionsThe worker_connections and worker_processes from the main section allows you to calculate max clients you can handle:max clients = worker_processes * worker_connectionsSo I understand thatworker_processesis single threaded and its value is helpful in CPU-intensive work, but I am unable to understand "allows you to handle max clients you can handle".If anyone can give an example as given inworker_processesit would be helpful for me to understand.
what is worker_processes and worker_connections in Nginx?
As stated in thenginx pitfallsyou should use server blocks andreturnstatements as they're way faster than evaluating RegEx vialocationblocks.Since you're forcing the rewrite rule to send a 301 there's no difference when it comes to SEO, btw..
I useNGINXin my dedicated server.I've a question about thereturnandrewrite 301.Rewrite 301:rewrite ^ http://xxx.xxxxx.net/xx-xxx/$request_uri? permanent;Return 301:location ~ redirect-this/?$ { return 301 http://xxx.xxxxx.net/xx-xxx/redirect-this$1; }All redirects work correctly. But..Which is the most effective method to make a 301 redirect?I've more than 200 url to redirect. So, what you recommend?
NGINX - Return 301 vs Rewrite
I was trying to create Let's Encrypt certificate using certbot for my sub-domain and had the following issue.Command:ubuntu@localhost:~$ certbot --nginx -d my_subdomain.website.com -d my_subdomain2.website.comIssue:The requested Nginx plugin does not appear to be installedSolution:Ubuntu 20+ubuntu@localhost:~$ sudo apt-get install python3-certbot-nginxEarlier Versionsubuntu@localhost:~$ sudo apt-get install python-certbot-nginx
I'm actually working on a webapp, I useReactjsfor the frontend andGolangfor the backend. Those 2 programs are hosted separately on 2 VMs onGoogle-Compute-Engine. I want to serve my app throughhttpsso I choose to useNginxfor serving the frontend in production. Firstly I made my config file forNginx:#version: nginx/1.14.0 (ubuntu) server { listen 80 default_server; listen [::]:80 default_server; root /var/www/banshee; server_name XX.XXX.XX.XXX; #public IP of my frontend VM index index.html; location / { try_files $uri /index.html =404; } }For this part everything works as expected but after that I want to serve my App overhttpsfollowingthis tutorial. I installed the packagessoftware-properties-common,python-certbot-apacheandcertbotbut when I triedsudo cerbot --nginx certonlyI get the following message:gdes@frontend:/etc/nginx$ sudo certbot --nginx certonly Saving debug log to /var/log/letsencrypt/letsencrypt.log Could not choose appropriate plugin: The requested nginx plugin does not appear to be installed The requested nginx plugin does not appear to be installedI made some searches on Google and here and I still can't figure out which plugin is missing or an other way to fix this.Does someone have an idea tohelp me ?Thanks a lot :)
Issue using certbot with nginx
I think you don't have your permissions set up correctly for /var/www Change the ownership of the folder.sudo chown -R $USER /var/www
I have got a virtual private server with nginx Virtual Hosts setup (Server Blocks).I've installed Git and got my ssh keys authenticated with GitHub.I have my website running in~/var/www/example.com/public_html/I tried to run:git clone[email protected]:example/example.co.uk.gitto pull my files on GitHub to the /public_html/ directory but I get the error:fatal: could not create work tree dir 'example.com'.: Permission deniedI've followed this tutorial including the same issue he has mentioned on the page, but it still won't work:http://machiine.com/2013/pulling-a-git-repo-from-github-to-your-ubuntu-server/I'm completely new to this, so your help would be much appreciated!
Could not create work tree dir 'example.com'.: Permission denied
You have to install pcre3:apt-get install libpcre3 libpcre3-devThe library is required for regular expressions support in the location directive and for the ngx_http_rewrite_module module.http://nginx.org/en/docs/install.html
after downloading and trying to configure nginx when um executing the command ./configure um getting this error./configure: error: the HTTP rewrite module requires the PCRE library. You can either disable the module by using --without-http_rewrite_module option, or install the PCRE library into the system, or build the PCRE library statically from the source with nginx by using --with-pcre= option.and I execute theapt-get build-dep nginxcommand um getting the following errorThe following packages have unmet dependencies: libgd2-noxpm-dev : Depends: libgd2-noxpm (= 2.0.36~rc1~dfsg-6ubuntu2) but it is not going to be installed E: Build-dependencies for nginx could not be satisfied.I dont have any idea about the libgd2-noxpm. This is my first time with nginx . how to overcome from this error . Thank you in advance
nginx ./configure error ubuntu 12.04
If you just requestphp7.0, it'll install Apache as default. Doapt-get install php7.0-fpmand it'll install as FPM instead, leaving something like nginx up to you.
I'm trying to get my server re-setup as a Lemp stackThe issue I am now running into is installing PHP 7withoutApache, since nGinx will be my webserver.So, I've addedppa:ondrej/php. ranapt-get update, and tried to install just php7.0 viaapt-get install php7.0--nodepsflag does not work, as I am on Ubuntu 15.10And I am presented with:The following extra packages will be installed: apache2 apache2-bin apache2-data apache2-utils libapache2-mod-php7.0 libapr1 libaprutil1 libaprutil1-dbd-sqlite3 libaprutil1-ldap liblua5.1-0 libqdbm14 php-common php-readline php7.0 php7.0-cli php7.0-common php7.0-json php7.0-opcache php7.0-readline Suggested packages: apache2-doc apache2-suexec-pristine apache2-suexec-custom php-pear php-user-cache The following NEW packages will be installed: apache2 apache2-bin apache2-data apache2-utils libapache2-mod-php7.0 libapr1 libaprutil1 libaprutil1-dbd-sqlite3 libaprutil1-ldap liblua5.1-0 libqdbm14 php php-common php-readline php7.0 php7.0-cli php7.0-common php7.0-json php7.0-opcache php7.0-readlineIdo not wantapache anywhere near my server, so how can I install php7 without it? Short of compiling from source (as this makes it difficult at best to keep it updated)
Ubuntu Server Installing PHP 7 WITHOUT Apache
Nginx has some web server functionality (e.g., serving static pages; SSL handling) that gunicorn does not, whereas gunicorn implements WSGI (which nginx does not).... Wait, why do we need two servers? Think of Gunicorn as the application web server that will be running behind nginx – the front- facing web server. Gunicorn is WSGI-compatible. It can talk to other applications that support WSGI, like Flask or Django.Source:https://realpython.com/blog/python/kickstarting-flask-on-ubuntu-setup-and-deployment/
This question already has answers here:Are a WSGI server and HTTP server required to serve a Flask app?(3 answers)Closed5 years ago.I want to use gunicorn for a REST API application with Flask/Python. What is the purpose of adding nginx here to gunicorn? The gunicorn site recommends using gunicorn with nginx.
What is the purpose of using nginx with gunicorn? [duplicate]
You can run flower with --auth flag, which will authenticate using a particular google email:celery flower[email protected]Edit 1:New version of Flower requires couple more flags and a registered OAuth2 Client withGoogle Developer Console:celery flower \[email protected]\ --oauth2_key="client_id" \ --oauth2_secret="client_secret" \ --oauth2_redirect_uri="http://example.com:5555/login"oauth2_redirect_urihas to be the actual flower login url, and it also has to be added to authorized redirect url's in Google Development Console.Unfortunately this feature doesn't work properly in current stable version0.7.2, but it is now fixed in development version0.8.0-devwith thiscommit.Edit 2:You can configure Flower usingbasic authentication:celery flower --basic_auth=user1:password1,user2:password2Then block 5555 port for all but localhost and configure reverse proxy fornginxor for apache:ProxyRequests off ProxyPreserveHost On ProxyPass / http://localhost:5555Then make sure proxy mod is on:sudo a2enmod proxy sudo a2enmod proxy_httpIn case you can't set it up on a separate subdomain, ex:flower.example.com(config above), you can set it up forexample.com/flower:run flower withurl_prefix:celery flower --url_prefix=flower --basic_auth=user1:password1,user2:password2in apache config:ProxyPass /flower http://localhost:5555Of course, make sure SSL is configured, otherwise there is no point :)
I am looking to use Flower (https://github.com/mher/flower) to monitor my Celery tasks in place of the django-admin as reccomended in their docs (http://docs.celeryproject.org/en/latest/userguide/monitoring.html#flower-real-time-celery-web-monitor). However, because I am new to this I am a little confused about the way Flower's page is only based on HTTP, and not HTTPS. How can I enable security for my Celery tasks such that any old user can't just visit the no-login-needed websitehttp://flowerserver.com:5555and change something?I have considered Celery'sown documentationon this, but they unfortunately there is no mention of how to secure Flower's api or web ui. All it says:[Need more text here]Thanks!Update:My question is in part a duplicate of here:How do I add authentication and endpoint to Django Celery Flower Monitoring?However, I clarify his question here by asking how to run it using an environment that includes nginx, gunicorn, and celery all on the same remote machine. I too am wondering about how to set up Flower's outside accessible url, but also would prefer something like https instead of http if possible (or some way of securing the webui and accessing it remotely). I also need to know if leaving Flower running is a considerable security risk for anyone who may gain access to Flower's internal API and what the best way for securing this could be, or if it should just be disabled altogether and used just on an as-needed basis.
Celery Flower Security in Production
error_pagehandles errors that are generated by nginx. By default, nginx will return whatever the proxy server returns regardless of http status code.What you're looking for isproxy_intercept_errorsThis directive decides if nginx will intercept responses with HTTP status codes of 400 and higher.By default all responses will be sent as-is from the proxied server.If you set this to on then nginx will intercept status codes that are explicitly handled by an error_page directive. Responses with status codes that do not match an error_page directive will be sent as-is from the proxied server.
I have a Sinatra application hosted with Unicorn, and nginx in front of it. When the Sinatra application errors out (returns 500), I'd like to serve a static page, rather than the default "Internal Server Error". I have the following nginx configuration:server { listen 80 default; server_name *.example.com; root /home/deploy/www-frontend/current/public; location / { proxy_pass_header Server; proxy_set_header Host $http_host; proxy_redirect off; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Scheme $scheme; proxy_connect_timeout 5; proxy_read_timeout 240; proxy_pass http://127.0.0.1:4701/; } error_page 500 502 503 504 /50x.html; }The error_page directive is there, and I have sudo'd as www-data (Ubuntu) and verified I cancatthe file, thus it's not a permission problem. With the above config file, andservice nginx reload, the page I receive on error is still the same "Internal Server Error".What's my error?
nginx not serving my error_page
After spending a lot of time on this, I finally figured it out. There are many references to Nginx and connection reset by peer. Most of them seemed to be related to PHP. I couldn't find an answer that was specific to Nginx and uwsgi.I finally found a reference to fastcgi and a 502 bad gateway error (https://support.plesk.com/hc/en-us/articles/213903705). That lead me to look for a buffer size limit in the uwsgi configuration which exists asbuffer-size. The default value is 4096. From the documentation, it says:If you plan to receive big requests with lots of headers you can increase this value up to 64k (65535).There are many ways to configure uwsgi, I happen to use a .ini file. So in my .ini file I tried:buffer-size=65535This fixed the problem. You can adjust that to taste. Maybe start with the max and work back until you have an acceptable value, or just leave it at the max.This was frustrating to track down because there was no error on the uwsgi side of things.
Environment is Nginx + uwsgi.Getting a 502 bad gateway error from Nginx on certain GET requests. Seems to be related to the length of the URL. In our particular case, it was a long list of GET parameters. Shorten the GET parameters and no 502 error.From the nginx/error.log[error] 22113#0: *1 recv() failed (104: Connection reset by peer) while reading response header from upstream, client: 192.168.1.100, server: server.domain.com, request: "GET "No information in the uwsgi error log.
Nginx uwsgi (104: Connection reset by peer) while reading response header from upstream
Found something that is working well :server { listen 8001 ssl; ssl_certificate /home/xxx/server.crt; ssl_certificate_key /home/xxx/server.key; error_page 497 301 =307 https://$host:$server_port$request_uri; location /{ proxy_pass http://localhost:8000; proxy_redirect off; proxy_set_header Host $host:$server_port; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_set_header X-Forwarded-Ssl on; } }
I use reverse proxy with Nginx and I want to force the request into HTTPS, so if a user wants to access the url with http, he will be automatically redirected to HTTPS.I'm also using a non-standard port.Here is my nginx reverse proxy config:server { listen 8001 ssl; ssl_certificate /home/xxx/server.crt; ssl_certificate_key /home/xxx/server.key; location / { proxy_pass https://localhost:8000; proxy_redirect off; proxy_set_header Host $host:$server_port; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_set_header X-Forwarded-Ssl on; proxy_set_header X-Forwarded-Proto https; } }I've tried many things and also read posts about it, includingthis serverfault question, but nothing has worked so far.
How to redirect on the same port from http to https with nginx reverse proxy
From readingsrc/core/ngx_log.cI guess the general error log format seems to beYYYY/MM/DD HH:MM:SS [LEVEL] PID#TID: *CID MESSAGEWithPIDandTIDbeing the logging process and thread id andCIDa number identifying a (probably proxied) connection, probably a counter. The*CIDpart is optional.
I want to parse NGINX error logs. However, there seems to be no documentation at all, concerning the used log format. While the meaning of some fields like the data is pretty obvious, some are not at all. In addition, I cannot be sure that my parser is complete if I do not have a documentation of all the possible fields. Since it seems you can change the access log format, but not that of the error log, I really have no idea how to get the information I need.Does anyone know of such a documentation?
NGINX error log format documentation
They aren't used in parallel. NGINX is areverse proxy. It's first in line. It accepts incoming connections and decides where they should go next. It also (usually) serves static media such as CSS, JS and images. It can also do other things such as encryption via SSL, caching etc.Gunicorn is the next layer and is anapplication server. NGINX sees that the incoming connection is forwww.domain.comand knows (via configuration files) that it should pass that connection onto Gunicorn. Gunicorn is aWSGIserver which is basically a:simple and universal interface between web servers and web applications or frameworksGunicorn's job is to manage and run the Django instance(s) (similar to usingdjango-admin runserverduring development)The contrast to this setup is to use Apache with themod_wsgimodule. In this situation, the application server is actually a part of Apache, running as a module.
A lot of Django app deployments over Amazon's EC2 use HTTP servers NGINX and Gunicorn.I was wondering what they actually do and why both are used in parallel. What is the purpose of running them both in parallel?
What is the purpose of NGINX and Gunicorn running in parallel?
I fixed it! I set the server name in different server blocks in nginx config. Remember to use docker port, not host port.server { listen 80; server_name game2048; location / { proxy_pass "http://game2048:8080"; } } server { listen 80; server_name game; location / { # Remember to refer to docker port, not host port # which is 9999 in this case: proxy_pass "http://game:8080"; } }The github repo has been updated to reflect the fix, the old readme file is there under./README.old01.md.Typical that I find the answer when I carefully phrase the question to others. Do you know that feeling?
I'm trying to have a docker container with nginx work as reverse proxy to other docker containers and I keep getting "Bad Gateway" on locations other other than the base location '/'.I have the following server block:server { listen 80; location / { proxy_pass "http://game2048:8080"; } location /game { proxy_pass "http://game:9999"; } }It works forhttp://localhostbut not forhttp://localhost/gamewhich gives "Bad Gateway" in the browser and this on the nginx container:[error] 7#7: *6 connect() failed (111: Connection refused) while connecting to upstream, client: 172.17.0.1, server: , request: "GET /game HTTP/1.1", upstream: "http://172.17.0.4:9999/game", host: "localhost"I use the official nginx docker image and put my own configuration on it. You can test it and see all details here:https://github.com/jollege/ngprox1Any ideas what goes wrong?NB: I have set local hostname entries on docker host to match those names:127.0.1.1 game2048 127.0.1.1 game
Docker nginx reverse proxy gives "502 Bad Gateway"
You can access cookie values by using the$cookie_COOKIE_NAME_GOES_HEREvariable.SeeNginx Documentation
I am new to Nginx and hope to get some help.I want to extract certain data (certain fields set by my PHP scripts) from browser cookie in nginx so that I can log it. If possible, I want to do this just by modifying nginx configuration.Any pointer/help would be greatly appreciated.
How to extract some value from cookie in nginx
Use strace. First, you need to detect PID of nginx process:# ps ax | grep nginx 25043 ? Ss 0:00 nginx: master process /usr/sbin/nginx -c /etc/nginx/nginx.conf 25044 ? S 0:02 nginx: worker processOk, so 25044 is the worker process. Now, we trace it:# strace -p 25044 2>&1 | grep gz open("/var/www/css/ymax.css.gz", O_RDONLY|O_NONBLOCK) = 438 open("/var/www/css/patches/patch_my_layout.css.gz", O_RDONLY|O_NONBLOCK) = -1 ENOENT (No such file or directory) open("/var/www/yaml/core/iehacks.css.gz", O_RDONLY|O_NONBLOCK) = -1 ENOENT (No such file or directory) open("/var/www/js/koznazna5.js.gz", O_RDONLY|O_NONBLOCK) = -1 ENOENT (No such file or directory) open("/var/www/css/ymax.css.gz", O_RDONLY|O_NONBLOCK) = 216As you can see, it is trying to find .gz versions of files.
How can I check that nginx is serving the .gz version of static files, if they exist?I compiled nginx with the gzip static module, but I don't see any mention of the .gz version being served in my logs. (I have minified global.js and global.css files with .gz versions of them in the same directory).The relevant part of nginx.conf looks like this:gzip on; gzip_static on; gzip_http_version 1.0; gzip_disable "MSIE [1-6]\."; gzip_vary on; gzip_comp_level 2; gzip_proxied any; gzip_types text/plain text/html text/css application/x-javascript text/xml application/xml application/xml+rss text/javascript;Any pointers would be appreciated.
How can I check that the nginx gzip_static module is working?
File probably is there:/usr/local/nginx/sbin/nginxto be sure You can do:ps aux | grep nginxTo kill process:sudo killall nginxAnd start again:/usr/local/nginx/sbin/nginx
Closed.This question does not meetStack Overflow guidelines. It is not currently accepting answers.This question does not appear to be abouta specific programming problem, a software algorithm, or software tools primarily used by programmers. If you believe the question would be on-topic onanother Stack Exchange site, you can leave a comment to explain where the question may be able to be answered.Closed2 years ago.This post was edited and submitted for review1 year agoand failed to reopen the post:Original close reason(s) were not resolvedImprove this questionI used thissh fileto install Nginx. When I modify thenginx.confand try to reload or restart Nginx it didn't restart. I used below command.sudo systemctl restart nginxgave mesudo: unable to resolve host localhost.localdomain sudo: systemctl: command not foundand this onesudo service nginx restart sudo: unable to resolve host localhost.localdomain nginx: unrecognized serviceand this onesudo /etc/init.d/nginx restart sudo: unable to resolve host localhost.localdomain sudo: /etc/init.d/nginx: command not found
How to restart Nginx in Ubuntu or other linux servers [closed]
As stated by Maxim Dounin inthe comments above:When nginx returns 400 (Bad Request) it will log the reason into error log, at "info" level. Hence an obvious way to find out what's going on is to configureerror_logto log messages at "info" level and take a look into error log when testing.
I have my site which is using nginx, and testing site with header testing tools e.g.http://www.webconfs.com/http-header-check.phpbut every time it says 400 bad request below is the out put from the tool. Though all my pages load perfectly fine in browser and when I see in chrome console it says status code 200OK.HTTP/1.1 400 Bad Request => Server => nginx Date => Fri, 07 Sep 2012 09:40:09 GMT Content-Type => text/html Content-Length => 166 Connection => closeI really don't understand what is the problem with my server config?A bit of googling suggests to increase the buffer size using, and I increased it to following:large_client_header_buffers 4 16k;The same results persist.Can some one guide me to the right direction?
How to fix nginx throws 400 bad request headers on any header testing tools?
It's probably easier to start afresh. Tutorial athttps://www.digitalocean.com/community/articles/how-to-install-and-configure-django-with-postgres-nginx-and-gunicorn.I got it running on a fresh ubuntu 14.04 droplet. Install python3 and django and then simply follow the tutorial. Didn't do the postgres or virtualenv bits though.
I'm trying to get Gunicorn to use Python3 for a Django app I want to make. I'm using Digital Ocean's Django image to get started. It comes with Django, Gunicorn, and Nginx installed and configured. The default Django project that comes with this image seems to work fine for Python 2.I'veapt-get'ed these packages.python3python3-psycopg2python3-devpython3-pipIn order to try to avoid any problems, I've also done this.pip uninstall djangopip3 install djangoIrm -rf'ed the stock project and created a new one withdjango-admin.py startproject django_project.django-admin.pyuses Python 3 (according to the shebang). Later, I usepython3 manage.py startapp django_appto create a new app.At this point, everything works fine. Just like the default app. Then, indjango_app/views.pyI do this and it breaks.from django.shortcuts import render from django.http import HttpResponse def index(request): # Python 2 and 3 - works fine # print('PRINTING') # Python 3 only - crashes print(1, 2, end=' ') return HttpResponse("Hello, world! This is my first view.")The error page says I'm using Python 2.7.6.Okay, so then I thought I could install Gunicorn through pip for Python 3, so I do this.pip uninstall gunicornpip3 install gunicornBut then I just end up with 502 Bad Gateway. When I doservice gunicorn status, I getgunicorn stop/waiting. I triedservice gunicorn restart, but it still saysgunicorn stop/waiting.I did awhich gunicornand it's installed at/usr/local/bin/gunicorn. Uhh... I'm not really sure what else I could try. Any help would be greatly appreciated. Thanks.
How to get Gunicorn to use Python 3 instead of Python 2 (502 Bad Gateway)
You could add a virtual host for app.example.com that listens on port 80 then proxy pass all requests to flask:server { listen 80; server_name app.example.com; location / { proxy_pass http://localhost:8142; } }
I know that this is a common question, and there are answers for the same, but the reason I ask this question is because I do not know how to approach the solution. Depending on the way I decide to do it, the solution I can pick changes. Anyways,I have an AWS EC2 instance. My DNS is handled by Route53 and I own example.com. Currently, on my instance, there are two services running:example.com:80 [nginx/php/wordpress] example.com:8142 [flask]What I want to do is, makeapp.example.compoint toexample.com:8142. How exactly do I go about doing this? I am pretty sure that I will have to pointapp.example.comto the same IP asexample.com, since it is the same box that will be serving it. And, nginx will be the first one to handle these requests at port 80. Is there a way with which I can make nginx forward all requests to localhost:8142?Is there a better way that I can solve this problem?
Redirect subdomain to port [nginx/flask]
Quoting from the documentation:Evan Miller has written the definitiveguide to Nginx module development. But some parts of it are a little out of date. You've been warned.A github search turned up theNginx Development Kit. It seems to be more up to date.From my own personal experience,Evan Miller's guidewas of a great help. You must also have a deep understanding of how NGINX works.Agentzh's tutorialcan help you.Reading the source code ofhis modulesis always helpful too.There is also avideo tutorialthat I haven't check yet, but it seems nice.
Closed.This question is seeking recommendations for software libraries, tutorials, tools, books, or other off-site resources. It does not meetStack Overflow guidelines. It is not currently accepting answers.We don’t allow questions seeking recommendations for software libraries, tutorials, tools, books, or other off-site resources. You can edit the question so it can be answered with facts and citations.Closed4 years ago.Improve this questionI'm trying to find tutorials on how to build a module/plugin for Nginx web server.Can someone help please, I just can't seem to find the appropriate tutorials.
How to write a Nginx module? [closed]
Create separately two files (you don't have to, but it will be much clearer) in/etc/nginx/sites-available/www.example.comand/etc/nginx/sites-available/api.example.comThe api.example.com file's content:server { listen 80; server_name api.example.com; root /var/www/api.example.com/html/example/app; #also add a root dir here location / { proxy_set_header Host $host; proxy_set_header X-Real-IP $remote_addr; proxy_pass http://127.0.0.1:3836; } }The www.example.com's content:server { listen 80 default_server; # listen [::]:80 default_server ipv6only=on; root /var/www/example.com/html/example/app; index index.html index.htm; # Make site accessible from http://localhost/ server_name www.example.com www.example.org; location / { # First attempt to serve request as file, then # as directory, then fall back to displaying a 404. try_files $uri $uri/ =404; # Uncomment to enable naxsi on this location # include /etc/nginx/naxsi.rules } location /bower_components { alias /var/www/example.com/html/example/bower_components; } location /scripts { alias /var/www/example.com/html/example/scripts; } location /content { alias /var/www/example.com/html/example/content; } location /api { proxy_set_header Host $host; proxy_set_header X-Real-IP $remote_addr; proxy_pass http://127.0.0.1:3836; } }And finally enable the domains:sudo ln -s /etc/nginx/sites-available/www.example.com /etc/nginx/sites-enabled/www.example.comandsudo ln -s /etc/nginx/sites-available/api.example.com /etc/nginx/sites-enabled/api.example.com
I want to runwww.example.comandapi.example.comon same port80.This is what I have. All my googles ping lead to the below code. But, this is not working.server { listen 80 default_server; # listen [::]:80 default_server ipv6only=on; root /var/www/example.com/html/example/app; index index.html index.htm; # Make site accessible from http://localhost/ server_name www.example.com www.example.org; location / { # First attempt to serve request as file, then # as directory, then fall back to displaying a 404. try_files $uri $uri/ =404; # Uncomment to enable naxsi on this location # include /etc/nginx/naxsi.rules } location /bower_components { alias /var/www/example.com/html/example/bower_components; } location /scripts { alias /var/www/example.com/html/example/scripts; } location /content { alias /var/www/example.com/html/example/content; } location /api { proxy_set_header Host $host; proxy_set_header X-Real-IP $remote_addr; proxy_pass http://127.0.0.1:3836; } } server { listen 80 server_name api.example.com location / { proxy_set_header Host $host; proxy_set_header X-Real-IP $remote_addr; proxy_pass http://127.0.0.1:3836; } }I do not know the reason. Any suggestions on this?
Nginx multiple server blocks listening to same port
As Stefano Fratini correctly pointed out in his answer, yourlocationdeclaration has an error: for regular expressions you should use~alone, not^~.Named captures are a feature of PCRE and they have different syntax available in different versions. For the syntax you use?you must have PCRE 7.0 at least.Please see the extensive information inofficial Nginx documentation
Let's say I have a URL like this:www.example.com/a/b/sth, and I write a location block in Nginx config:location ^~ /a/b/(?[a-zA-Z]+) { # use variable $myvar here if ($myvar = "sth") { ... } }I hope to be able to use variable$myvarcaptured from the URLinsidethe block, however, Nginx keeps telling me this variable is not defined and won't start:nginx: [emerg] unknown "myvar" variable
variable capture in Nginx location matching
The issue ended up being uwsgi's forking.When working with multiple processes with a master process, uwsgi initializes the application in the master process and then copies the application over to each worker process. The problem is if you open a database connection when initializing your application, you then have multiple processes sharing the same connection, which causes the error above.The solution is to set thelazyconfiguration option for uwsgi, which forces a complete loading of the application in each process:lazySet lazy mode (load apps in workers instead of master).This option may have memory usage implications as Copy-on-Write semantics can not be used. When lazy is enabled, only workers will be reloaded by uWSGI’s reload signals; the master will remain alive. As such, uWSGI configuration changes are not picked up on reload by the master.There's also alazy-appsoption:lazy-appsLoad apps in each worker instead of the master.This option may have memory usage implications as Copy-on-Write semantics can not be used. Unlike lazy, this only affects the way applications are loaded, not master’s behavior on reload.This uwsgi configuration ended up working for me:[uwsgi] socket = /tmp/my_app.sock logto = /var/log/my_app.log plugins = python3 virtualenv = /path/to/my/venv pythonpath = /path/to/my/app wsgi-file = /path/to/my/app/application.py callable = app max-requests = 1000 chmod-socket = 666 chown-socket = www-data:www-data master = true processes = 2 no-orphans = true log-date = true uid = www-data gid = www-data # the fix lazy = true lazy-apps = true
I'm trying to setup an application webserver using uWSGI + Nginx, which runs a Flask application using SQLAlchemy to communicate to a Postgres database.When I make requests to the webserver, every other response will be a 500 error.The error is:Traceback (most recent call last): File "/var/env/argos/lib/python3.3/site-packages/sqlalchemy/engine/base.py", line 867, in _execute_context context) File "/var/env/argos/lib/python3.3/site-packages/sqlalchemy/engine/default.py", line 388, in do_execute cursor.execute(statement, parameters) psycopg2.OperationalError: SSL error: decryption failed or bad record mac The above exception was the direct cause of the following exception: sqlalchemy.exc.OperationalError: (OperationalError) SSL error: decryption failed or bad record macThe error is triggered by a simpleFlask-SQLAlchemymethod:result = models.Event.query.get(id)uwsgiis being managed bysupervisor, which has a config:[program:my_app] command=/usr/bin/uwsgi --ini /etc/uwsgi/apps-enabled/myapp.ini --catch-exceptions directory=/path/to/my/app stopsignal=QUIT autostart=true autorestart=trueanduwsgi's config looks like:[uwsgi] socket = /tmp/my_app.sock logto = /var/log/my_app.log plugins = python3 virtualenv = /path/to/my/venv pythonpath = /path/to/my/app wsgi-file = /path/to/my/app/application.py callable = app max-requests = 1000 chmod-socket = 666 chown-socket = www-data:www-data master = true processes = 2 no-orphans = true log-date = true uid = www-data gid = www-dataThe furthest that I can get is that it has something to do with uwsgi's forking. But beyond that I'm not clear on what needs to be done.
uWSGI, Flask, sqlalchemy, and postgres: SSL error: decryption failed or bad record mac
Edit:As Alexey Ten didn't add a new answer, I'll edit mine to give his better answer in this case.if ($http_user_agent ~ "MSIE [67]\.")Original answer:Nginx doesn't allow multiple or nested if statements however you can do this :set $test 0; if ($http_user_agent ~ "MSIE 6\.0") { set $test 1; } if ($http_user_agent ~ "MSIE 7\.0") { set $test 1; } if ($test = 1) { rewrite ^ ${ROOT_ROOT}ancient/ last; }It is not shorter but it allows you to do the check and put the rewrite rule only once.Alternative answer:In some cases, you can also use | (pipe)if ($http_user_agent ~ "(MSIE 6\.0)|(MSIE 7\.0)") { rewrite ^ ${ROOT_ROOT}ancient/ last; }
For example, I want to do this:if ($http_user_agent ~ "MSIE 6.0" || $http_user_agent ~ "MSIE 7.0" (etc, etc)) { rewrite ^ ${ROOT_ROOT}ancient/ last; break; }instead of this:if ($http_user_agent ~ "MSIE 6.0") { rewrite ^ ${ROOT_ROOT}ancient/ last; break; } if ($http_user_agent ~ "MSIE 7.0") { rewrite ^ ${ROOT_ROOT}ancient/ last; break; }Nginx rejects this syntax (minus the (etc, etc)), and I don't see anything in the docs about this.Also, we opted not to use $ancient_browser directive, so that's not an option.
How can I rewrite this nginx "if" statement?
I finally found the answer: After I generated thedistfolder.I created a file calledStaticfileand put it in the dist folderI openedStaticfile& I added this linepushstate: enabledpushstate enabled keeps browser-visible URLs clean for client-side JavaScript apps that serve multiple routes. For example, pushstate routing allows a single JavaScript file route to multiple anchor-tagged URLs that look like /some/path1 instead of /some#path1.
I Have an Angular application. I run the commandng build --prod --aotto generate thedistfolder. In the dist folder I created a file namedStaticfilethen I uploaded the dist folder topivotal.iowith the following commands:cf push name-app --no-startcf start name-appThe app runs well. I have a nav bar, so when I change the path with navbar everything works fine. But when I do it manually (I enter the url myself) I have this error404 Not Found nginx. This my app.component.ts:const appRoutes: Routes = [ { path: 'time-picker', component: TimePickerComponent }, { path: 'material-picker', component: MaterialPickerComponent }, { path: 'about', component: AboutComponent }, { path: 'login', component: LoginComponent }, { path: 'registration', component: RegistrationComponent }, { path: '', redirectTo: '/time-picker', pathMatch: 'full' } ]; @NgModule({ declarations: [ AppComponent, TimePickerComponent, MaterialPickerComponent, DurationCardComponent, AboutComponent, LoginComponent, RegistrationComponent, ], imports: [RouterModule.forRoot( appRoutes // ,{ enableTracing: true } // <-- debugging purposes only ), FormsModule, BrowserAnimationsModule, BrowserModule, MdCardModule, MdDatepickerModule, MdNativeDateModule, MdInputModule ], providers: [{ provide: DateAdapter, useClass: CustomDateAdapter }], bootstrap: [AppComponent] }) export class AppModule { constructor(private dateAdapter: DateAdapter) { this.dateAdapter.setLocale('fr-br'); } }
Deploy single page application Angular: 404 Not Found nginx
Add ‘client_max_body_size xxM’ inside the http section in /etc/nginx/nginx.conf, where xx is the size (in megabytes) that you want to allow.http { client_max_body_size 20M; }
I use nginX/1.6 and laravel when i posted data to server i get this error 413 Request Entity Too Large. i tried many solutions as bellow1- set client_max_body_size 100m; in server and location and http in nginx.conf. 2- set upload_max_filesize = 100m in php.ini 3- set post_max_size = 100m in php.iniAfter restarting php5-fpm and nginx the problem still not solved
413 Request Entity Too Large
Jetty and Tomcat are web-containers, while Geronimo, Glassfish and JBoss support the whole J2EE stack (more or less). And, tataaa, they use/include Tomcat or Jetty for web-containers. The most important part of a fullblown J2EE server besides the web-container used to be theEJB-container allowing for deployment of EJBs, having them run in a transactional context etc. Today, J2EE is actually called Java EE. Entity EJBs (JPA) can run outside the EJB-container, say in Tomcat, but then outside the transaction handling that an EJB-container would provide.
As someone new to the Java EE ecosystem, I'm confused with these products which share a tremendous amount of keywords. And half of them come from Apache software foundation.Can someone address me with a brief distinctive explanation for each of them?
Jetty, Tomcat, Nginx, Geronimo, Glassfish: I'm confused
I think when you first set up nginx it comes with adefaultvirtual host. Did you try removing that? Did you try deleting the symlink? A third option would be to add adeny all;on the location/of the default virtual host.I am not exactly sure if that will work and I cannot test it right now. If the above does not work, try this out:http://nginx.org/en/docs/http/request_processing.html#how_to_prevent_undefined_server_nameshttp://your-server-ip/is a request with undefined server name. You should be able to block it with:server { listen 80; server_name ""; return 444; }
At my ubuntu server, I install nginx and setup virtual host using this article.https://www.digitalocean.com/community/articles/how-to-set-up-nginx-virtual-hosts-server-blocks-on-ubuntu-12-04-lts--3The virtual host's domain name is like www.example.com. When I go to www.example.com, I can see my application's index page. However, when I go to the real ip address, I still see the nginx welcome page. What can I do to remove this welcome page or point to www.example.com if someone uses ip address to access my site?I setup a A record to point ip xxx.xxx.xxx.xxx to www.example.com.
remove default nginx welcome page when access directly from ip address
Use$upstream_addrand you will get, for example,127.0.0.1:8000orunix:/home/my_user/www/my_site/tmp/.unicorn.sock
We use Nginx as a reverse proxy with this setup:upstream frontends { server 127.0.0.1:8000; server 127.0.0.1:8001; server 127.0.0.1:8002; [...] } server { location / { proxy_pass http://frontends; [...] } [...] }As part of the access log, I would like to record the upstream server that has served the request, which in our case just means the associated localhost port.The variables in the documentation (http://wiki.nginx.org/HttpProxyModule#Variables) mention $proxy_host and $proxy_port but in the log they always end up with the values "frontends" and "80".
How to record reverse proxy upstream server serving request in Nginx log?
There is no way to (at least as of now). Full request will be always buffered before nginx will start sending it to an upstream. To track uploaded files you may tryupload progressmodule.Update: in nginx 1.7.11 theproxy_request_bufferingdirective is available, which allows to disable buffering of a request body. It should be used with care though, see docs.
I configured nginx as reverse proxy to my node.js application for file uploads with proxy_pass directive. It works, but my problem is that nginx waits for the whole file body to be uploaded before passing it to the upstream. This causes problems for me, because I want to track upload progress at my application. Any idea how to configure nginx in order to stream file body in real time to the upstream?
nginx files upload streaming with proxy_pass
restarting the container is not advisable when you initialize Docker Swarm because it may remove the nginx service. So if you need an alternative asidedocker restart; You can go inside the container and just runnginx -s reloadFor example, in docker env, if you have the container namednginxdocker exec nginx -s reload
I want to add/remove servers in my nginx running inside a docker containerI use ADD command in Dockerfile to add my nginx.conf to /etc/nginx dir.# Copy a configuration file from the current directory ADD nginx.conf /etc/nginx/then in my running nginx container that have a conf like this# List of application servers upstream app_servers { server 172.17.0.91:9000; server 172.17.0.92:9000; server 172.17.0.93:9000; }how do restart my nginx to take effect of the edited nginx.conf?thank you in advance!
restart nginx container when upstream servers is updated
Just stumbled here and managed to get things working with this free open source alternative:https://nssm.cc/It basically is just a GUI to help you create a service. Steps I used:Download NGinx (http://nginx.org/en/download.html) and uzip to C:\foobar\nginxDownload nssm (https://nssm.cc/)Run "nssm install nginx" from the command lineIn NSSM gui do the following:On the application tab: set path to C:\foobar\nginx\nginx.exe, set startup directory to C:\foorbar\nginxOn the I/O tab type "start nginx" on the Input slow. Optionally set C:\foobar\nginx\logs\service.out.log and C:\foobar\nginx\logs\service.err.log in the output and error slots.Click "install service". Go to services, start "nginx". Hithttp://localhost:80and you should get the nginx logon. Turn off the service, disable browser cache and refresh, screen should now fail to load.You should be good to go from then on.
I am trying to run nginx (reverse proxy) as a windows service so that it's possible to proxy a request even when a user is not connected.I searched a lot around and foundwinswthat should create a service from an .exe file (such as nginx).i found many tutorials online saying to create an xml file as following nginx nginx nginx c:\nginx\nginx.exe c:\nginx\ roll -p c:\nginx -p c:\nginx -s stop (i have nginx.exe in a folder called nginx under c: o the paths are correct).Now the problem is that the service is created but i can't seem to make it start, every time i try to start it a windows pops up sayingError 1053: The service didn't respond to the start or control request in a timely fashionDoes anyone know how can i fix this or a different way to run nginx as a window service?
run nginx as windows service
server_namemust match hostname inlink/scriptURLs. Either declare your configuration as default for this interface:port pair (listen 8000 default)Nginx must listen on the interface where your host's IP is bound (seems ok in your case)
I'm using apache+mod_wsgi for django.And all css/js/images are served throughnginx.For some odd reason, when others/friends/colleagues try accessing the site, jquery/css is not getting loaded for them, hence the page looks jumbled up.My html files use code like this - My nginx configuration insites-availableis like this -server { listen 8000; server_name localhost; access_log /var/log/nginx/aa8000.access.log; error_log /var/log/nginx/aa8000.error.log; location / { index index.html index.htm; } location /static/ { autoindex on; root /opt/aa/webroot/; } }There is a directory/opt/aa/webroot/static/which have correspondingcss&jsdirectories.The odd thing is that the pages show fine when I access them.I have cleared my cache/etc, but the page loads fine for me, from various browsers.Also, I don't see 404 any error in the nginx log files.Any pointers would be great.
django : Serving static files through nginx
Put this before your other location block:location ~* \.(?:ico|css|js|gif|jpe?g|png)$ { expires 30d; add_header Vary Accept-Encoding; access_log off; }That should work.You could also use this:## All static files will be served directly. location ~* ^.+\.(?:css|cur|js|jpe?g|gif|htc|ico|png|html|xml|otf|ttf|eot|woff|woff2|svg)$ { access_log off; expires 30d; add_header Cache-Control public; ## No need to bleed constant updates. Send the all shebang in one ## fell swoop. tcp_nodelay off; ## Set the OS file cache. open_file_cache max=3000 inactive=120s; open_file_cache_valid 45s; open_file_cache_min_uses 2; open_file_cache_errors off; }
I'm having some trouble defining a rule to cache my static files. I've found this solution:location ~* \.(ico|js|css|png|gif|jpe?g)$ { expires 7d; }which actually looks like what I need. The problem is, if I include this code into my NGINX.conf, no static files are delivered anymore and my site is blank. Any ideas/hints what might cause this result? Maybe I have to add, that the static files are distributed in different directories :/. My NGINX config file looks like this:server { server_name bla.domain.com; listen 80; root /var/repo/; location / { default_type text/html; index index.html; if ($request_method !~ ^(GET)$ ) { return 444; } if ($http_user_agent ~* LWP::Simple|BBBike|wget) { return 403; } if ( $http_referer ~* (babes|forsale|girl|jewelry|love|nudit|organic|poker|porn|sex|teen) ) { return 403; } } location /bf/football/ { alias /var/repos/f20; } location /bf/f20/ { alias /var/repo/f20; } location /bf/zoo/ { alias /var/repo/zoo/; } location /kbloader/ { alias /var/repo/kbloader/; } }Would be nice if someone could help me out with this or point me in the right direction.
Nginx static files location block not working when added to nginx.conf?
for development:express, mainly because of flexibility it provides... you can change your static location and structure very easily during developmentfor production:nginx, because its much much faster. Node/express are good for executing logic, but for serving raw content... nothing can beat nginx. You also get additional capabilities such as gzip, load balancing...Nevertheless, this question has been asked in stackoverflow a number of times already: seenode.js itself or nginx frontend for serving static files?orUsing Node.js only vs. using Node.js with Apache/NginxorWhich is most efficient : serving static files directly by nginx or by node via nginx reverse proxy?
I'm building a Node.js applications and I'm using nginx as a reverse proxy. My application has some static files I need to serve and a Socket.io server.I know that I can serve static files directly with Express (using express.static middleware). Also I can point nginx directly to the directory where my static files are located, so they would be served by nginx.So, the question: which one is the better approach? Which pros and cons can I face while using each approach?
What's the better approach: serving static files with Express or nginx?
It is becauseyou have used--nameswitch.container is stopped and not removedYou find it stoppeddocker ps -aYou can simply start it using below command:docker start webserverEDIT: AlternativesIf you want to start the container with below command each time,docker run -d -p 80:80 --name webserver nginxthen use one of the following:method 1:use--rmswitch i.e., container gets destroyed automatically as soon as it is stoppeddocker run -d -p 80:80 --rm --name webserver nginxmethod 2:remove it explicitly after stopping the container before starting the command that you are currently using.docker stop docker rm
I first got my nginx docker image:docker pull nginxThen I started it:docker run -d -p 80:80 --name webserver nginxThen I stopped it:docker stop webserverThen I tried to restart it:$docker run -d -p 80:80 --name webserver nginx docker: Error response from daemon: Conflict. The container name "/webserver" is already in use by container 036a0bcd196c5b23431dcd9876cac62082063bf62a492145dd8a55141f4dfd74. You have to remove (or rename) that container to be able to reuse that name.. See 'docker run --help'.Well, it's an error. But in fact there's nothing in container list now:docker container list CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMESWhy I restart nginx image failed? How to fix it?
docker restart container failed: "already in use", but there's no more docker image
You should never share your private key. You should consider the key you posted here compromised and generate a new key and signing request.You have a certificate request and not an actual signed certificate. You provide the request ('CSR') to the signing party. They use that request to create a signed certificate ('CRT') which they then make available to you. The key is never disclosed to anyone.
I have to add ssl (https) for a website, I was given a SSL.CSR and a SSL.KEY file. I 'dos2unix'ed them (because they have trailing ^M) and copied them to the server(CSR -> mywebsite.crt, KEY -> mywebsite.key). I did the following modification to nginx.conf:@@ -60,8 +60,13 @@ } server { - listen 80; + listen 443; server_name ...; + ssl on; + ssl_certificate mywebsite.crt; + ssl_certificate_key mywebsite.key; + ssl_session_cache shared:SSL:10m; + ssl_session_timeout 10m; # Set the max size for file uploads to 500Mb client_max_body_size 500M;Error happens when I restart nginx:nginx: [emerg] PEM_read_bio_X509_AUX("/etc/nginx/mywebsite.crt") failed (SSL: error:0906D06C:PEM routines:PEM_read_bio:no start line:Expecting: TRUSTED CERTIFICATE)I figure it's because the first line of mywebsite.crt file contains 'REQUEST', so I remove 'REQUEST' from the first and last of the lines, and restart nginx again, and hit another error:nginx: [emerg] PEM_read_bio_X509_AUX("/etc/nginx/mywebsite.crt") failed (SSL: error:0D0680A8:asn1 encoding routines:ASN1_CHECK_TLEN:wrong tag error:0D06C03A:asn1 encoding routines:ASN1_D2I_EX_PRIMITIVE:nested asn1 error error:0D08303A:asn1 encoding routines:ASN1_TEMPLATE_NOEXP_D2I:nested asn1 error:Field=algorithm, Type=X509_ALGOR error:0D08303A:asn1 encoding routines:ASN1_TEMPLATE_NOEXP_D2I:nested asn1 error:Field=signature, Type=X509_CINF error:0D08303A:asn1 encoding routines:ASN1_TEMPLATE_NOEXP_D2I:nested asn1 error:Field=cert_info, Type=X509 error:0906700D:PEM routines:PEM_ASN1_read_bio:ASN1 lib)Any idea?
nginx fails to load ssl certificate
You're getting the path wrong forproxy_params99% of the time (From my experience), the default location for theproxy_paramsfile is/etc/nginx/proxy_paramsbut that doesn't seem to be the same for you.Theproxy_paramsfile contains the following:proxy_set_header Host $http_host; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_set_header X-Forwarded-Proto $scheme;These parameters are used to forward information to the application that you're proxying to. I've worked with an oldCentOSserver that didn't have aproxy_paramsfile, Instead of creating one myself, I just included these parameters directly; and location block looked like this:location / { proxy_set_header Host $http_host; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_set_header X-Forwarded-Proto $scheme; proxy_pass http://unix:/home/sammy/myproject/myproject.sock; }So it's up to you. If the file exists in another location just include it with the right location:include /path/to/proxy_paramselse you can include the params directly in the location block (Like I did above)Or create one yourself and place it in/etc/nginx(If you want to stick with your current code)
I try to deploy a django project with Nginx and Gunicorn withthis tutorial. i did all to-dos but, when i create/etc/nginx/sites-available/myprojectfile with below code:server { listen 80; server_name server_domain_or_IP; location = /favicon.ico { access_log off; log_not_found off; } location /static/ { root /home/sammy/myproject; } location / { include proxy_params; proxy_pass http://unix:/home/sammy/myproject/myproject.sock; } }and then runsudo nginx -tfor find errors, i get this error:nginx: [emerg] open() "/etc/nginx/proxy_params" failed (2: No such file or directory) in /etc/nginx/sites-enabled/myproject:11 nginx: configuration file /etc/nginx/nginx.conf test failedHow can I solve the problem?
django- nginx: [emerg] open() "/etc/nginx/proxy_params" failed (2: No such file or directory) in /etc/nginx/sites-enabled/myproject:11
Check the permissions on the directory /home/Foo/log/nginx/. It must be writable by nginx. Set permissions like so:sudo chmod 766 /home/Foo/log/nginx
The below is my nginx configuration file located in/etc/nginx/nginx.confuser Foo; worker_processes 1; error_log /home/Foo/log/nginx/error.log; pid /home/Foo/run/nginx.pid; events { worker_connections 1024; use epoll; } http { access_log /home/Foo/log/nginx/access.log; server { listen 80; location = / { proxy_pass http://192.168.0.16:9999; } } }As you can see I change log, pid files location into home directory.When I re-startLinuxit seems to work,Nginxrecords error logs in the file I set and pid file also.However, when it triesnginx -s reloador the other, It tries to open other error log file.nginx: [alert] could not open error log file: open() "/var/log/nginx/error.log" failed (13: Permission denied) 2015/12/14 11:23:54 [warn] 3356#0: the "user" directive makes sense only if the master process runs with super-user privileges, ignored in /etc/nginx/nginx.conf:1 nginx: the configuration file /etc/nginx/nginx.conf syntax is ok 2015/12/14 11:23:54 [emerg] 3356#0: open() "/home/Foo/run/nginx.pid" failed (13: Permission denied) nginx: configuration file /etc/nginx/nginx.conf test failedI know, I can solve permission error withsudobut the main issue in here is a error log file(/var/log/nginx/error.log) Nginx tries to open.Why does it try to access another error log file?
Nginx still try to open default error log file even though I set nginx config file while reloading
If the iframe pages are always in the same directory, simple prefix locations could be used.server { listen 443; location /l/ { # redirect https iframe requests to http server return 301 http://$server_name$request_uri; } # ... } server { listen 80; location / { # the default location redirects to https return 301 https://$server_name$request_uri; } location /l/ {} # do not redirect requests for iframe location # ... }
I have a website which should only be reachable over HTTPS except one URL-pattern (because I have on some pages http-iframe's and I would like to avoid security warnings)E.g. this pages should be redirected to https: http://example.com http://example.com/a/this-is-an-article http://example.com/v/this-is-a-video This pages should not be redirected to https (or should be redirected form https to http) http://example.com/l/page-with-unsafe-iframe http://example.com/l/other-page-with-unsafe-iframe
nginx: redirect everything from http to https, except one url-pattern
Have a look at the following config option fromnginx docs:Syntax:disable_symlinks off; disable_symlinks on | if_not_owner [from=part];Default: disable_symlinks off;Context: http, server, locationThis directive appeared in version 1.1.15.
I have installed nginx on Ubuntu 12.04. However, nginx does not seem to follow symlinks. I understand that there is a config change required for this but I am not able to find where to make the change. Any help appreciated.
Nginx not following symlinks
You need the http:// prefix on your unix: path, as in:proxy_pass http://unix:/home/david/StockSearch/stocksearch/stocksearch.sock;Seehttp://nginx.org/en/docs/http/ngx_http_proxy_module.html
I have a really basic nginx setup which is failing for some reason;server { listen 80; server_name librestock.com; location = /favicon.ico { access_log off; log_not_found off; } location /static/ { root /home/david/StockSearch/stocksearch; } location / { include proxy_params; proxy_pass unix:/home/david/StockSearch/stocksearch/stocksearch.sock; } }according to everything I've read I'm setting the server name correctly. when I replace librestock.com with the ip of the server it works.error:$ nginx -t nginx: [emerg] invalid URL prefix in /etc/nginx/sites-enabled/stocksearch:12 nginx: configuration file /etc/nginx/nginx.conf test failed
Nginx invalid URL prefix
Yes, add '127.0.0.1 sub.localhost' to your hosts file. That sub has to be resolved somehow. That should work.Then once you're ready to go to the net, yes, add an a or cname record for the subdomain sub.When I use proxy_pass I also include the proxy.conf from nginx.http://wiki.nginx.org/HttpProxyModule
I want to test nginx subdomains before uploading config to the server. Can i test it on localhost? I tryserver { listen 80; server_name localhost; location / { proxy_pass http://localhost:8080; } } server { listen 80; server_name sub.localhost; location / { proxy_pass http://localhost:8080/sub; } }And it does not work. Shoulld i change my hosts file in order to make it work? Also, after uploading site to the server should i change DNS records and add sub.mydomain.com?
How to test nginx subdomains on localhost
You can't specify your own format, but in nginx build-in several level's of error_log-ing.Syntax:error_log file [ debug | info | notice | warn | error | crit ]Default:${prefix}/logs/error.logSpecifies the file where server (and fastcgi) errors are logged.Default values for the error level:in the main section - errorin the HTTP section - critin the server section - critIn my error_log, time always presented int begin of each error string in log.
I can specify custom log format foraccess_logon Nginx, but it doesn't work forerror_log.Is there anyway to achieve this?
Is it possible to specify custom error log format on Nginx?
It looks like you may be missing a semicolon at the end of thessl_certificate_keyline.
I have got my EV SSL Certificate. I am following tutorials on how to use my certificate with NGINX on UbuntuWhen I am trying to restart my nginx, I get:**invalid number of arguments in "ssl_certificate_key" directive in /etc/nginx/sites-enabled/defaultWhat I did so far:sudo nano /etc/nginx/sites-enabled/default upstream app { # Path to Unicorn SOCK file, as defined previously server unix:/home/zhall/zoulfia/shared/sockets/unicorn.sock fail_timeout=0; } server { listen 80; server_name moneytree.space www.moneytree.space " " 178.62.19.65; rewrite ^/(.*) https://moneytree.space/$1 permanent; } # HTTPS server server { listen 443; server_name moneytree.space www.moneytree.space " " 178.62.19.65; root /home/zhall/zoulfia/public; ssl on; ssl_certificate /home/zhall/moneytree.space.chained.crt; **ssl_certificate_key /home/zhall/ moneytree.space.key** ssl_session_timeout 10m; ssl_protocols SSLv3 TLSv1 TLSv1.1 TLSv1.2; ssl_ciphers "HIGH:!aNULL:!MD5 or HIGH:!aNULL:!MD5:!3DES"; ssl_prefer_server_ciphers on; location / { try_files $uri $uri/ =404; } }When i restart nginx with ---sudo service nginx restartIn my log file ----sudo nano /var/log/nginx/error.log, I get: **invalid number of arguments in "ssl_certificate_key" directive in /etc/nginx/sites-enabled/defaultEverything is new to me so I need your help to solve this. What am I doing wrong and most importantly how to correct this mistake?Thank you, Zoulfia
invalid number of arguments in "ssl_certificate_key" directive in /etc/nginx/sites-enabled/defaul
Translate all of the Lua source code files to object files and put them in a static library:for f in *.lua; do luajit -b $f `basename $f .lua`.o done ar rcus libmyluafiles.a *.oThen link thelibmyluafiles.alibrary into your main program using-Wl,--whole-archive -lmyluafiles -Wl,--no-whole-archive -Wl,-E.This line forces the linker to include all object files from the archive and to export all symbols.For example, a file named foo.lua can now be loaded withlocal foo = require("foo")from within your application.Details about the-boption can be found onRunning LuaJIT.
How can I compile myLuascripts into a single executable file, while also gaining the super fast performance benefits ofLuaJIT?Background:My Lua scripts are for a web application I created (e.g. to hosthttp://example.com)My current technology stack is NGINX (web server), Lua/LuaJIT (language to retrieve dynamic content)I have around 50+.luafiles that make up my web application (from Models/Views/Controllers)FreeBSD 9 operating systemFor simplicity sake in deployment, I'd like to compile down all of my .lua scripts that run my web application down to a single executable.Is this possible and how?It appears that Lua official comes with a library calledSRLuaWhat are the negatives to compiling down my .lua to a single executable (e.g. would performance be worse, etc)?
How to compile Lua scripts into a single executable, while still gaining the fast LuaJIT compiler?
The simplest way to do this is with anifdirective. If there is a better way, please let me know, as people say theifdirective is inefficient. Nginx converts dashes to underscores in headers, soX-Forwarded-Protobecomes$http_x_forwarded_proto.server { listen 80; server_name example.com; # Replace this with your own hostname if ($http_x_forwarded_proto = "http") { return 301 https://example.com$request_uri; } # Rest of configuration goes here... }
I'm hosting a website behind a Cloudflare proxy, which means that all requests to my server are over port 80, even though Cloudflare handles HTTP (port 80) and HTTPS (port 443) traffic.To distinguish between the two, Cloudflare includes anX-Forwarded-Protoheader which is set to "http" or "https" based on the user's connection.I would like to redirect every request with anX-Forwarded-Proto: httpheader to the SSL version of my site. How can I achieve this with an nginx configuration?
How to make nginx redirect based on the value of a header?
server { server_name example.com; root /path/to/root; location / { # bla bla } location /demo { alias /path/to/root/production/folder/here; } }If you need to usetry_filesinside/demoyou'll need to replacealiaswith arootand do a rewrite because of the bugexplained here
basically an server instance is running atsomesite.com/production/folder/here?param=here&count=1I want to pointsomeite.com/demoto/production/folder/hereso when user typessomesite.com/production/demo?param=hereit will work without redirecting to/production/folder/here
nginx: how to create an alias url route?
Proxy pass should be ip and port of your webpack-dev-server container and you needproxy_redirect off;location /sockjs-node { proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $remote_addr; proxy_set_header Host $host; proxy_pass http://node:8080; proxy_redirect off; proxy_http_version 1.1; proxy_set_header Upgrade $http_upgrade; proxy_set_header Connection "upgrade"; }Also don't forget to add poll to your webpack-dev middlewarewatchOptions: { aggregateTimeout: 300, poll: 1000 }
I'm trying to getwebpack-dev-serverrunning inside a Docker container then accessing it through a NGINX host. The initialindex.htmlloads but the Web Sockets connection to the dev server cannot connect.VM47:35 WebSocket connection to 'ws://example.com/sockjs-node/834/izehemiu/websocket' failed: Error during WebSocket handshake: Unexpected response code: 400I'm using the following config.map $http_upgrade $connection_upgrade { default upgrade; '' close; } upstream webpack_dev_server { server node; } server { server_name _; listen 80; root /webpack_dev_server; location / { proxy_pass http://webpack_dev_server; } location /sockjs-node/ { proxy_pass http://webpack_dev_server/sockjs-node/; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_set_header Host $host; # pass the host header - http://wiki.nginx.org/HttpProxyModule#proxy_pass proxy_http_version 1.1; # recommended with keepalive connections - http://nginx.org/en/docs/http/ngx_http_proxy_module.html#proxy_http_version # WebSocket proxying - from http://nginx.org/en/docs/http/websocket.html proxy_set_header Upgrade $http_upgrade; proxy_set_header Connection $connection_upgrade; } }
Webpack Dev Server with NGINX proxy_pass
Just tested that @home, and actually multiple configuration additions are needed:1/ Run the keycloak container with env-e PROXY_ADDRESS_FORWARDING=trueas explained in the docs, this is required in a proxy way of accessing to keycloak:docker run -it --rm -p 8087:8080 --name keycloak -e PROXY_ADDRESS_FORWARDING=true jboss/keycloak:latestAlso explained in thisSO question2/ Change theweb-contextinside keycloak's configuration file$JBOSS_HOME/standalone/configuration/standalone.xmlDefault keycloak configuration points toauthauthThen you could change it tokeycloak/authkeycloak/authIf you need to automate this for docker, just create a new keycloak image :FROM jboss/keycloak:latest USER jboss RUN sed -i -e 's/auth<\/web-context>/keycloak\/auth<\/web-context>/' $JBOSS_HOME/standalone/configuration/standalone.xml3/ Add some proxy information to nginx configuration (mostly for http / https handling)location /keycloak { proxy_pass http://example.com:8087; proxy_set_header Host $host; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-Proto $scheme; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; }If you are proxying requests from nginx to keycloak on same server, I recommend usingproxy_pass http://localhost:8087;, and if not try to use a private network to avoid proxying through external web requests.Hope this helps
How can I set thedocker keycloak base urlas parameter ?I have the following nginx reverse proxy configuration:server { listen 80; server_name example.com; location /keycloak { proxy_pass http://example.com:8087/; } }When I try to accesshttp://example.com/keycloak/I got a keycloak http redirect tohttp://example.com/auth/instead ofhttp://example.com/keycloak/auth/Any ideas?
Configure reverse-proxy for Keycloak docker with custom base URL
Missing includes innginx.confinclude /usr/local/etc/nginx/sites-enabled/*;http://wiki.nginx.org/CoreModule#include
I'm trying to set up a simple virtual host, serving only static files. Trouble is, directing the browser to (in this case)jorum.devdisplays the default nginx welcome page, as opposed tojorum.dev/index.html.Nginx was installed using Homebrew on Mac OS X Mountain Lion.hosts127.0.0.1 jorum.devjorum.devserver { listen 80; server_name jorum.dev; location / { root ~/Sites/jorum; index index.html index.htm; } }nginx.confworker_processes 1; events { worker_connections 1024; } http { include mime.types; default_type application/octet-stream; sendfile on; gzip on; gzip_disable "msie6"; gzip_min_length 1100; gzip_vary on; gzip_proxied any; gzip_buffers 16 8k; gzip_types text/plain text/css application/json application/x-javascript text/xml application/xml application/rss+xml text/javascript image/svg+xml application/x-font-ttf font/opentype application/vnd.ms-fontobject; server_tokens off; client_max_body_size 4096k; client_header_timeout 10; client_body_timeout 10; keepalive_timeout 10 10; send_timeout 10; server { listen 80; server_name localhost; location / { root html; index index.html index.htm; } #error_page 404 /404.html; # redirect server error pages to the static page /50x.html # error_page 500 502 503 504 /50x.html; location = /50x.html { root html; } } }
Nginx only shows welcome page
Ifrewrite_log on;is used then the rewrite information will be logged toerror_logatnoticelevel. There is no separate log file.
When you turn on the nginx rewrite log withrewrite_log on;, where does the system actually log that info? It doesn't seem to be in the documentation, and a decent search through google doesn't turn anything up.I have also tried enabling and looking in both the access and error logs. No luck.
Where does nginx store the rewrite_log?
I think the greatest benefit is that you're then able to use the same port (80) for multiple applications. Otherwise, you'd need a new IP address for each nodejs application you have. Depending on how you set things up, you can also configure different folders and subdomains to different nodejs apps running on different ports. If you're building something big or complex, this is pretty great. Imagine being able to run your APIs on one node application, your website from another, and the logged-in website (member's area, dashboard, etc.) in another app. Your load balancer can determine who needs to go where (example.com/api* -> api.js, example.com/dashboard* -> dashboard.js, example.com -> app.js). This is not only useful for scaling, but also when things break, not everything breaks at once.To the maturity thing, meh. Nodejs +forever+node-http-proxy= Amazing. Run 1 proxy server for all of your apps with a minimal config/complexity (lower chance of failure). Then have fun with everything else. Don't forget to firewall off your internal ports, though;).Some people make note of load balancing, which true, is a benefit. However, load balancing isn't something that most people will benefit from, since a single threaded, non-blocking nodejs thread can handle quite impressively large loads. I truly wouldn't even consider this as a difference if I were you. Load balancing is easy enough to implement when you need it, but otherwise utterly useless until you do.Also note, if you do go with a non-node proxy solution (nginx, tornado, etc.), just be sure NOT to use one that blocks.Apache blocks.Nginx doesn't. You don't want to throw away one of the greatest benefits of using nodejs in the first place on a crummy server.
What are the advantages of having nginx or another web-server running as a reverse-proxy in front of the Node.JS? What does it provide?(This question is intended for matters concerning web-apps, not web-pages).Thank you.
Advantages of a reverse proxy in front of Node.JS
I believe you need to changevue.config.jsmodule.exports = { devServer: { disableHostCheck: true } }
I was running a vuejs app on its own dev server, now I can access the site by public IP of machine, But after pointing it with a domain using nginx its showing an error loop in consoleerror in consoleInvalid Host header [WDS] Disconnected!Due to this the script,style injection and auto reload not working.config of dev serverdev: { assetsSubDirectory: "static", assetsPublicPath: "/", disableHostCheck: true, host: "0.0.0.0", // '192.168.2.39',//can be overwritten by process.env.HOST port: 8080, autoOpenBrowser: false, errorOverlay: false, notifyOnErrors: false, poll: true, devtool: "cheap-module-source-map", cacheBusting: true, cssSourceMap: true },nginx config for the domainserver { listen 80 ; listen [::]:80; server_name prajin.prakash.com; location / { proxy_pass http://localhost:8081; } }
Vuejs app showing Invalid host header error loop
In most cases you don't need a custom module, you can simply set a header with a combination of embedded variables of http_core_module which is (most probably) unique. Example:location / { proxy_pass http://upstream; proxy_set_header X-Request-Id $pid-$msec-$remote_addr-$request_length; }This would yield a request id like "31725-1406109429.299-127.0.0.1-1227" and should be "unique enough" to serve as a trace id.
I'm using nginx as a load balancer in front of several upstream app servers and I want to set a trace id to use to correlate requests with the app server logs. What's the best way to do that in Nginx, is there a good 3rd party module for this?Otherwise a pretty simple way would be to base it off of timestamp (possibly plus a random number if that's not precise enough) and set it as an extra header on the request, but the only set_header command I see in the docs is for setting a response header.
Setting a trace id in nginx load balancer
Use an upstream block instead of the container name directlyupstream backend { server container1; } server { location ~ ^/some_url/(.*)$ { proxy_pass http://backend/$1; } }This should allow normal name resolution to occur providing a way to easily use docker links with nginx.
I have two docker containers with nginx. container1 is linked to container2. Docker then adds an entry to/etc/hostswhich I entered into the nginx configuration like so:server { location ~ ^/some_url/(.*)$ { proxy_pass http://container1/$1; } }I can pingcontainer1fromcontainer2, but nginx cannot resolve it:*1 no resolver defined to resolve container1How can I proxy_pass a request to another docker container?
nginx proxy_pass to a linked docker container
Make your Dockerfile something as below -FROM php:7-fpm WORKDIR /var/www RUN apt-get update && apt-get install -y libmcrypt-dev mysql-client && docker-php-ext-install mcrypt pdo_mysql ADD . /var/www RUN chown -R www-data:www-data /var/wwwThis makes directory/var/wwwowned bywww-datawhich is the default user forphp-fpm.Since it is compiled with userwww-data.Ref-https://github.com/docker-library/php/blob/57b41cfc2d1e07acab2e60d59a0cb19d83056fc1/7.0/jessie/fpm/Dockerfile
I have two docker containers: Nginx and App.The app container extends PHP-fpm and also has my Laravel Code.In mydocker-compose.ymlI'm doing:version: '2' services: nginx: build: context: ./nginx dockerfile: ./Dockerfile ports: - "80:80" links: - app app: build: context: ./app dockerfile: ./DockerfileIn my Nginx Dockerfile i'm doing:FROM nginx:latest WORKDIR /var/www ADD ./nginx.conf /etc/nginx/conf.d/default.conf ADD . /var/www EXPOSE 80In my App Dockerfile I'm doing:FROM php:7-fpm WORKDIR /var/www RUN apt-get update && apt-get install -y libmcrypt-dev mysql-client && docker-php-ext-install mcrypt pdo_mysql ADD . /var/wwwAfter successfully running docker-compose up, I have the following error when I try localhostThe stream or file "/var/www/storage/logs/laravel.log" could not be opened: failed to open stream: Permission deniedFrom my understanding, the storage folder needs to writable by the webserver.What should I be doing to resolve this?
Permission Denied Error using Laravel & Docker
I got it... the private key file used with nginx mustnothave a passphrase. I removed the passphrase and it worked.
Closed.This question isnot about programming or software development. It is not currently accepting answers.This question does not appear to be abouta specific programming problem, a software algorithm, or software tools primarily used by programmers. If you believe the question would be on-topic onanother Stack Exchange site, you can leave a comment to explain where the question may be able to be answered.Closed1 year ago.The community reviewed whether to reopen this question1 year agoand left it closed:Original close reason(s) were not resolvedImprove this questionI'm trying to set up SSL on Nginx. It doesn't work, and I am getting the following error in the error log, which is getting passed up from the OpenSSL library which nginx was compiled with. I don't know what that library is, but it's version 0.8.54 of nginx, and I installed it using apt-get on Ubuntu Linux.2012/02/21 07:06:33 [emerg] 4071#0: SSL_CTX_use_PrivateKey_file("/exequias/certs/exequias.com.key") failed (SSL: error:0906406D:PEM routines:PEM_def_callback:problems getting password error: 0906A068:PEM routines:PEM_do_header:bad password read error:140B0009:SSL routines: SSL_CTX_use_PrivateKey_file:PEM lib)I have ensured that the file permissions on the private key file are not stopping nginx from reading it. It is an RSA private key, generated withopenssl rsa.Any ideas what might be causing this?
What does "SSL_CTX_use_PrivateKey_file" "problems getting password error" indicate in Nginx error log? [closed]
location = /favicon.ico { log_not_found off; }
How to I get rid of all the below errors in nginx. I do not have a favicon.ico2012/03/11 17:13:25 [error] 959#0: *116 open() "/usr/local/nginx/html/favicon.ico" failed (2: No such file or directory), client: 111.68.59.75, server: 127.0.0.1, request: "GET /favicon.ico HTTP/1.1"I would imagine some line in nginx conf?
Nginx and favicon.ico - "GET /favicon.ico HTTP/1.1" FAILED