You are not logged in.

#1 2017-06-08 01:10:22

felixtheratruns
Member
Registered: 2016-12-04
Posts: 21

nginx and php-fpm [SOLVED] (but still welcome more insight)

So installed nginx and php-fpm but the odd thing is that I have no "sites-enabled" or "sites-available" directories.

This is my /etc/nginx/nginx.conf

 
#user html;
#worker_processes  1;

#error_log  logs/error.log;
#error_log  logs/error.log  notice;
#error_log  logs/error.log  info;

#pid        logs/nginx.pid;

#stuff arch made me add

user http;
worker_processes auto;
worker_cpu_affinity auto;
pcre_jit on;

events {
    worker_connections  2048; #changed from 1024
}

http {
    include mime.types;
    default_type application/octet-stream;
    sendfile on;
    tcp_nopush on;
    aio threads;
    server_tokens off; # Security: Disables nginx version in error messages and in the “Server” response header field.
    charset utf-8; # Force usage of UTF-8
    index index.php index.html index.htm;
    # include servers-enabled/*; # See Server blocks
    server {    
        listen 80; 
        server_name localhost; 


        location ~ [^/]\.php(/|$) {
            root /srv/http/www;
            index index.php;
            fastcgi_split_path_info ^(.+?\.php)(/.*)$;
            if (!-f $document_root$fastcgi_script_name) {
                return 404;
            }
    
            # Mitigate https://httpoxy.org/ vulnerabilities
            fastcgi_param HTTP_PROXY "";
    
            #fastcgi_pass 127.0.0.1:9000;
            fastcgi_pass unix:/var/run/php-fpm/php-fpm.sock;
            fastcgi_index index.php;
            include fastcgi_params;
        }
    
    }

}

but when I  go to localhost it still is looking for things in the wrong document root and I don't see where I could have set

journalctl -ex

Jun 07 21:13:12 EMOO nginx[23492]: 2017/06/07 21:13:12 [error] 23494#23494: *1 open() "/etc/nginx/html/favicon.ico" failed (2: No such file or directory), client: 127.0.0.1, server: localhost, request: "GET /favicon.ico HTTP/1.1", host: "localhost", referrer: "http://localhost/"

when I symlink it there:
sudo ln -s  /usr/share/nginx/html /etc/nginx/html
I get this in the logs if I don't have a favicon, but otherwise I don't get anything

Jun 07 21:04:35 EMOO nginx[389]: 2017/06/07 21:04:35 [error] 400#400: *48 open() "/etc/nginx/html/favicon.ico" failed (2: No such file or directory), client: 127.0.0.1, server: localhost, request: "GET /favicon.ico HTTP/1.1", host: "localhost", referrer: "http://localhost/"

and this appears:

Welcome to nginx!

If you see this page, the nginx web server is successfully installed and working. Further configuration is required.

For online documentation and support please refer to nginx.org.
Commercial support is available at nginx.com.

Thank you for using nginx.

https://ibb.co/ca318F

There seems to be something wrong, do you know what that is, why I don't have a sites-enabled or a sites-available, and how do I change my document root? Thanks.

Last edited by felixtheratruns (2017-06-08 04:06:18)

Offline

#2 2017-06-08 03:39:57

felixtheratruns
Member
Registered: 2016-12-04
Posts: 21

Re: nginx and php-fpm [SOLVED] (but still welcome more insight)

just tried folowing this tutorial: https://support.rackspace.com/how-to/in … e-sockets/
but changing it for my file structure.
and I get this when I go to localhost in my browser:

This site can’t be reached

localhost refused to connect.
Try:
Checking the connection
Checking the proxy and the firewall
ERR_CONNECTION_REFUSED
ReloadHIDE DETAILS

/etc/nginx/nginx.conf

user http;
worker_processes 4;
#pid /var/run/nginx.pid;

events {
  worker_connections 768;
  # multi_accept on;
}

http {
# Basic Settings
  sendfile on;
  tcp_nopush on;
  tcp_nodelay on;
  keepalive_timeout 65;
  types_hash_max_size 2048;
  # server_tokens off;

  # server_names_hash_bucket_size 64;
  # server_name_in_redirect off;

  include /etc/nginx/mime.types;
  default_type application/octet-stream;

# Logging Settings
log_format gzip '$remote_addr - $remote_user [$time_local]  '
          '"$request" $status $bytes_sent '
          '"$http_referer" "$http_user_agent" "$gzip_ratio"';

    access_log /var/log/nginx/access.log gzip buffer=32k;
    error_log /var/log/nginx/error.log notice;

# Gzip Settings
    gzip 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;

# Virtual Host Configs
  include /etc/nginx/conf.d/*.conf;
  include /etc/nginx/sites-enabled/*;

}


/etc/php/php-fpm.d/localhost.conf

[localhost]

listen = /var/run/php-fpm/localhost.socket
listen.backlog = -1
listen.owner = http 
listen.group = http
listen.mode=0660

; Unix user/group of processes
user = http 
group = http

; Choose how the process manager will control the number of child processes.
pm = dynamic
pm.max_children = 75
pm.start_servers = 10
pm.min_spare_servers = 5
pm.max_spare_servers = 20
pm.max_requests = 500

; Pass environment variables
env[HOSTNAME] = $HOSTNAME
env[PATH] = /usr/local/bin:/usr/bin:/bin
env[TMP] = /tmp
env[TMPDIR] = /tmp
env[TEMP] = /tmp

; host-specific php ini settings here
; php_admin_value[open_basedir] = /srv/http/localhost:/tmp

symlinked the file:
ls -l /etc/nginx/sites-enabled/localhost

lrwxrwxrwx 1 root root 36 Jun  7 23:30 /etc/nginx/sites-enabled/localhost -> /etc/nginx/sites-available/localhost

/etc/nginx/sites-available/localhost

server {
  server_name  localhost;
  rewrite ^(.*) http://localhost$1 permanent;
}

server {
        listen 80;
        server_name localhost;
              root   /srv/http/localhost;
              index index.php;
#        include /etc/nginx/security;

# Logging --
access_log  /var/log/nginx/localhost.access.log;
error_log  /var/log/nginx/localhost.error.log notice;

        # serve static files directly
        location ~* ^.+.(jpg|jpeg|gif|css|png|js|ico|html|xml|txt)$ {
              access_log        off;
              expires           max;
        }

        location ~ \.php$ {
        try_files $uri =404;
              fastcgi_pass unix:/var/run/php-fpm/localhost.socket;
              fastcgi_index index.php;
              include /etc/nginx/fastcgi_params;
        }
}             

output of:
journalctl -ex

-- Unit nginx.service has begun starting up.
Jun 07 23:31:29 EMOO nginx[6923]: 2017/06/07 23:31:29 [warn] 6923#6923: conflicting server name "localhost" on 0.0.0.0:80, ignored
Jun 07 23:31:29 EMOO systemd[1]: Started A high performance web server and a reverse proxy server.
-- Subject: Unit nginx.service has finished start-up
-- Defined-By: systemd
-- Support: http://lists.freedesktop.org/mailman/listinfo/systemd-devel
-- 
-- Unit nginx.service has finished starting up.
-- 
-- The start-up result is done.
Jun 07 23:31:29 EMOO sudo[6888]: pam_unix(sudo:session): session closed for user root
Jun 07 23:35:54 EMOO sudo[5081]: pam_unix(sudo:session): session closed for user root
Jun 07 23:37:59 EMOO kernel: perf: interrupt took too long (2544 > 2500), lowering kernel.perf_event_max_sample_rate to 7860

Last edited by felixtheratruns (2017-06-08 15:06:28)

Offline

#3 2017-06-08 03:55:28

felixtheratruns
Member
Registered: 2016-12-04
Posts: 21

Re: nginx and php-fpm [SOLVED] (but still welcome more insight)

TO BE VERY CLEAR: this is for the setup that I had in my reply, NOT the setup in my original post.


well silly me, had to change /etc/nginx/sites-enabled/localhost

server {
  server_name  localhost;
  rewrite ^(.*) http://localhost$1 permanent;
}

to

server {
  server_name  www.localhost;
  rewrite ^(.*) http://localhost$1 permanent;
}

and here's the file I tested it with: (the file and all the directories it is in are owned by root, yeah not sure why that works with the http user that is set, I guess http is just the process the server runs under)
/srv/http/localhost/index.php

<html>
 <head>
  <title>PHP Test</title>
 </head>
 <body>
 <?php echo '<p>Hello World</p>'; ?> 
 </body>
</html>

TO BE VERY CLEAR: this is for the setup that I had in my reply, NOT the setup in my original post.

Last edited by felixtheratruns (2017-06-08 04:04:41)

Offline

Board footer

Powered by FluxBB