Multiple Nginx master process - nginx

When i run my nginx server with command:
/usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf
I have two master process
root 11632 2.6 0.1 76164 1372 ? Ss 01:30 0:06 nginx: master process /usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf
www 14515 3.0 24.0 319920 245060 ? S 01:35 0:00 nginx: worker process
www 14516 3.0 24.0 319920 245060 ? S 01:35 0:00 nginx: worker process
www 14517 3.0 24.0 319920 245232 ? S 01:35 0:00 nginx: worker process
www 14518 0.0 6.5 319920 66544 ? R 01:35 0:00 nginx: master process /usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf
A part of my nginx.conf:
user www www;
worker_processes 4;
error_log /data/logs/nginx_error.log crit;
pid /usr/local/nginx/logs/nginx.pid;
worker_rlimit_nofile 600000;
events
{
use epoll;
worker_connections 600000;
}
When worker_processes less than 4, the ps aux | grep nginx | grep -v grep looks good. If worker_process is 4, it will have two master processes.

Related

nginx: [alert] kill(57200, 1) failed (3: No such process)

When I am executing this command:
./nginx -s reload
Throw error:
nginx: [alert] kill(57200, 1) failed (3: No such process)
when I open the nginx.pid file:
vim /usr/loca/nginx/logs/nginx.pid
the process id is:57200.But when I am checking nginx process,it does not have master process,the output is:
[root#localhost logs]# ps -aux|grep nginx
Warning: bad syntax, perhaps a bogus '-'? See /usr/share/doc/procps-3.2.8/FAQ
root 12191 0.0 0.0 28172 8956 ? S Aug29 3:54 nginx: worker process
root 12192 0.0 0.0 28172 8960 ? S Aug29 3:53 nginx: worker process
root 12193 0.0 0.0 28436 9272 ? S Aug29 3:46 nginx: worker process
root 12194 0.0 0.0 28172 8948 ? S Aug29 3:55 nginx: worker process
root 12195 0.0 0.0 28436 9156 ? S Aug29 3:56 nginx: worker process
root 12196 0.0 0.0 28172 8944 ? S Aug29 3:49 nginx: worker process
root 12197 0.0 0.0 28172 8988 ? S Aug29 3:58 nginx: worker process
root 12198 0.0 0.0 27908 8740 ? S Aug29 3:42 nginx: worker process
root 12199 0.0 0.0 27908 8744 ? S Aug29 3:39 nginx: worker process
root 53760 0.0 0.0 103252 832 pts/1 S+ 22:14 0:00 grep nginx
root 80835 0.0 0.0 27908 8740 ? S Aug31 2:30 nginx: worker process
What's wrong? How to solve this problem? The nginx version is 1.10.2.
I also faced similar issue on nginx 1.10.2.
Instead of ./nginx -s reload, I used ./nginx to start nginx and it solved this issue.

How to host ASP.NET Core 2.0 (Kestrel) with Unix domain socket behind a nginx proxy?

I am current using ASP.NET Core 2.0 behind nginx through HTTP requests in Ubuntu 16.
And I'd like to switch to Unix domain socket.
In my Program.cs I have:
var host = default(IWebHost);
var builder = new WebHostBuilder()
.UseKestrel(opt =>
{
if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux) && settings.Config.ListenUnixSocket)
{
opt.ListenUnixSocket("/tmp/api.sock");
}
})
.Configure(app =>
{
app.Map("/health", b => b.Run(async context =>
{
context.Response.StatusCode = (int)HttpStatusCode.OK;
await context.Response.WriteAsync("Ok");
}));
});
if(RuntimeInformation.IsOSPlatform(OSPlatform.Windows) || !settings.Config.ListenUnixSocket)
{
host = builder.UseUrls("http://0.0.0.0:5501").Build();
}
else
{
host = builder.Build();
}
host.Run();
And, at Nginx:
location /health {
#proxy_pass http://127.0.0.1:5501;
proxy_pass http://unix:/tmp/api.sock:/;
}
Running it using the default TCP socket works, but switching to Unix domain sockets, I got a 502 error.
Do I need any specific module at nginx? What I am doing wrong?
Aspnetcore will create api.socket when its running but Nginx must have permission to write.
So, if you don't know what user nginx uses, execute:
ps aux | grep nginx
You'll get something this in the terminal:
root 5005 0.0 0.2 125116 1460 ? Ss 20:12 0:00 nginx: master process /usr/sbin/nginx -g daemon on; master_process on;
www-data 5006 0.0 0.6 125440 3260 ? S 20:12 0:00 nginx: worker process
root 5173 0.0 0.1 14516 920 pts/0 S+ 20:17 0:00 grep --color=auto nginx
Then you set the permission:
sudo chown www-data:www-data /tmp/api.sock
And, that's it!
#Apolineo correctly identified that the Unix socket's permissions need to be opened up to allow other users to connect to the socket.
However, a better solution than manually setting the permissions is to do it programmatically from Main immediately after the socket is created.
Example solution in this answer.

openresty nginx, there is no work process after starting nginx

I work on windows 10 use built-in bash for ubantu
I installed openresty, and start it's nginx with command "nginx -p openresty-test".
My nginx.conf content is:
worker_processes 2;
error_log logs/error.log;
events {
worker_connections 1024;
}
http {
server {
listen 6699;
location / {
default_type text/html;
content_by_lua_block {
ngx.say("HelloWorld")
}
}
}
}
problem:
I try curl "http://localhost:6699 -i", It's blocked without any message and didn't return.
I use web browser to visit localhost:6699, It's blocked too.
I run "ps -ef | grep nginx" show:
27 1 0 2433 ? 00:00:00 nginx: master process ng
29 2 0 2433 ? 00:00:00 grep --color=auto nginx
As we see there is only a master process, no any work process, I doubt that cause my problem,
how should I do?

Unable to load ZF2 with correct(?) include_path

So, I'm still newbie for all Unix stuff and now I face a problem which make me mad :) I also asking my friend, more experienced programmer, but he cant find answer too.
So, I trying to start zf2 application based on zend-skeleton with nginx and php5-fpm.
$ sudo service nginx status
* nginx is running
$ sudo service php5-fpm status
php5-fpm start/running, process 3389
$ ps aux | grep php
root 3389 0.0 0.3 145520 13624 ? Ss 15:40 0:00 php-fpm: master process (/etc/php5/fpm/php-fpm.conf)
www-data 3392 0.0 0.1 145520 4968 ? S 15:40 0:00 php-fpm: pool www
www-data 3393 0.0 0.1 145520 5324 ? S 15:40 0:00 php-fpm: pool www
somebud+ 3551 0.0 0.0 5908 840 pts/1 S+ 15:55 0:00 grep --color=auto php
$ ps aux | grep nginx
somebud+ 3172 0.5 0.6 184412 24944 ? Sl 15:33 0:07 gedit /etc/nginx/nginx.conf
root 3368 0.0 0.0 15196 1092 ? Ss 15:40 0:00 nginx: master process /usr/sbin/nginx
www-data 3369 0.0 0.0 15720 2080 ? S 15:40 0:00 nginx: worker process
www-data 3370 0.0 0.0 15376 1516 ? S 15:40 0:00 nginx: worker process
www-data 3371 0.0 0.0 15376 1516 ? S 15:40 0:00 nginx: worker process
www-data 3372 0.0 0.0 15376 1516 ? S 15:40 0:00 nginx: worker process
somebud+ 3554 0.0 0.0 5908 840 pts/1 S+ 15:55 0:00 grep --color=auto nginx
This is my /etc/nginx/sites-available/testing.dom
server {
listen 80;
server_name testing.dom;
root /var/www/testing.dom/public_html/CommunicationApp/public/;
index index.php index.html index.htm;
location / {
try_files $uri $uri/ /index.php$is_args$args;
}
location ~ .*\.(php|phtml)?$ {
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param APPLICATION_ENV development;
fastcgi_pass unix:/var/run/php5-fpm.sock;
fastcgi_index index.php;
}
location ~ .*\.(git|jpg|jpeg|png|bmp|swf|ico)?$ {
expires 30d;
}
location ~ .*\.(js|css)?$ {
expires 1h;
}
location ~ /\.ht {
deny all;
}
}
My include_path is in the /etc/php5/fpm/php.ini like this:
; UNIX: "/path1:/path2"
include_path = ".:/usr/share/php:/var/www/testing.dom/public_html/library/Zend"
This is what in this Zend folder:
$ sudo ls /var/www/testing.dom/public_html/library/Zend/
Authentication Code Db Escaper Filter InputFilter Log Mime Paginator Server Stdlib Uri XmlRpc
Barcode Config Debug EventManager Form Json Mail ModuleManager Permissions ServiceManager Tag Validator
Cache Console Di Feed Http Ldap Math Mvc ProgressBar Session Test Version
Captcha Crypt Dom File I18n Loader Memory Navigation Serializer Soap Text View
Is this right library folder?
And this is my /var/www/testing.dom/public_html/CommunicationApp/public/index.php
chdir(dirname(__DIR__));
$temp = get_include_path();
var_dump($temp);
// Decline static file requests back to the PHP built-in webserver
if (php_sapi_name() === 'cli-server' && is_file(__DIR__ . parse_url($_SERVER['REQUEST_URI'], PHP_URL_PATH))) {
return false;
}
// Setup autoloading
require '../CommunicationApp/init_autoloader.php';
// Run the application!
Zend\Mvc\Application::init(require 'config/application.config.php')->run();
So, if I enter testing.dom in browser I got still this:
string(62) ".:/usr/share/php:/var/www/testing.dom/public_html/library/Zend"
And nothing else.
And this is nginx error.log:
2014/10/17 16:11:29 [error] 3369#0: *8 FastCGI sent in stderr: "PHP message: PHP Fatal error: Uncaught exception 'RuntimeException' with message 'Unable to load ZF2. Run `php composer.phar install` or define a ZF2_PATH environment variable.' in /var/www/testing.dom/public_html/CommunicationApp/init_autoloader.php:53
Stack trace:
#0 /var/www/testing.dom/public_html/CommunicationApp/public/index.php(17): require()
#1 {main}
thrown in /var/www/testing.dom/public_html/CommunicationApp/init_autoloader.php on line 53" while reading response header from upstream, client: 127.0.0.1, server: testing.dom, request: "GET / HTTP/1.1", upstream: "fastcgi://unix:/var/run/php5-fpm.sock:", host: "testing.dom"
Problem was solved! If you got such headache try to define your ZF2_PATH in fastcgi_params like this:
fastcgi_param ZF2_PATH /var/www/testing.dom/public_html/library/;

nginx reload config with multiple servers

I'm serving some demos in isolation like:
/demo1/-- nginx.conf
|- index.html
|- ...
#run
/demo1$ sudo nginx -c `pwd`/nginx.conf
and
/demo2/-- nginx.conf
|- index.html
|- ...
#run
/demo2$ sudo nginx -c `pwd`/nginx.conf
now I have the following nginx processes:
$ ps aux | grep nginx
root 3434 0.0 0.0 85904 1340 ? Ss 12:02 0:00 nginx: master process nginx -c /demo1/nginx.conf
nobody 3435 0.0 0.0 86316 2272 ? S 12:02 0:00 nginx: worker process
root 5096 0.0 0.0 85904 1344 ? Ss 11:21 0:00 nginx: master process nginx -c /demo2/nginx.conf
nobody 5097 0.0 0.0 86316 2272 ? S 11:21 0:00 nginx: worker process
I believe (tell me if I'm wrong) that if I reload the configuration this way:
$ sudo nginx -s reload
It will only deliver the message to the last master process that was spun.
How do I reload the configuration on a specific master process?
After reading the manpage I believe it has some to do with the -g option but I'm not sure how. Should I specify a static PID or something?
Here is my nginx.conf for reference
user nobody;
worker_processes 1;
events {
worker_connections 1024;
}
http {
include /etc/nginx/mime.types;
server {
listen 8000;
location / {
root /demoX;
index index.html index.htm;
}
}
}
You can use a signal to certain PID:
kill -QUIT 3434
Reload option is a reference to QUIT signal which reloads the config and spawn new worker.

Resources