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.
Related
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.
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?
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.
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/;
I'm confused
2014/05/12 09:36:51 [error] 25928#0: *1 open() "/home/dev/OpenWrt-ImageBuilder-brcm47xx-for-linux-x86_64/packages/test.html" failed (13: Permission denied), client: 128.68.154.57, server: localhost, request: "GET /test.html HTTP/1.1"
here is permissions
[root#vsfedora OpenWrt-ImageBuilder-brcm47xx-for-linux-x86_64]# namei -l /home/dev/OpenWrt-ImageBuilder-brcm47xx-for-linux-x86_64/packages/test.html
f: /home/dev/OpenWrt-ImageBuilder-brcm47xx-for-linux-x86_64/packages/test.html
dr-xr-xr-x root root /
drwxr-xr-x root root home
drwxrwx--- dev dev dev
drwxr-xr-x dev dev OpenWrt-ImageBuilder-brcm47xx-for-linux-x86_64
drwxr-xr-x dev dev packages
-rw-rw-r-- dev dev test.html
here is group
dev:x:1000:nginx
nginx worker process working as nginx user
[root#vsfedora ~]# ps aux|grep nginx
root 26494 0.0 0.3 111588 3796 ? Ss 11:07 0:00 nginx: master process /usr/sbin/nginx
nginx 26495 0.0 0.5 111932 5116 ? S 11:07 0:00 nginx: worker process
server section in nginx.conf:
server {
location / {
autoindex on;
root /usr/share/nginx/html;
}
symlink is also fine
lrwxrwxrwx. 1 0 0 65 May 12 10:10 packages -> /home/dev/OpenWrt-ImageBuilder-brcm47xx-for-linux-x86_64/packages
it's a SELinux issue
tail /var/log/audit/audit.log
type=AVC msg=audit(1399879586.183:2081199): avc: denied { search } for pid=26495 comm="nginx" name="dev" dev="dm-1" ino=269277 scontext=system_u:system_r:httpd_t:s0 tcontext=unconfined_u:object_r:user_home_dir_t:s0 tclass=dir
type=SYSCALL msg=audit(1399879586.183:2081199): arch=c000003e syscall=2 success=no exit=-13 a0=7fdd65ed2219 a1=800 a2=0 a3=0 items=0 ppid=26494 pid=26495 auid=4294967295 uid=996 gid=1000 euid=996 suid=996 fsuid=996 egid=1000 sgid=1000 fsgid=1000 ses=4294967295 tty=(none) comm="nginx" exe="/usr/sbin/nginx" subj=system_u:system_r:httpd_t:s0 key=(null)
detailed explanation and resolution can be found here
Per documentation on user directive, nginx uses group name equal to user name if you omit group name. So you have to explicitly use user nginx dev; in your nginx.conf.