2

I am pretty new in Nginx and I have a problem with it. I have two wordpress websites and I want to start them with Nginx on a Centos Linux. What I have done is:

  1. creating sites-available and sites-enabled in the /etc/nginx/
  2. Put my website configuration files (.conf) into sites-available
  3. I created symbolic links for them using ln -s

My configuration files are as follow: nginx.conf

http {
    log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
                      '$status $body_bytes_sent "$http_referer" '
                      '"$http_user_agent" "$http_x_forwarded_for"';

    access_log  /var/log/nginx/access.log  main;

    sendfile            on;
    tcp_nopush          on;
    tcp_nodelay         on;
    keepalive_timeout   65;
    types_hash_max_size 2048;

    default_type        application/octet-stream;

    # Load modular configuration files from the /etc/nginx/conf.d directory.
    # See http://nginx.org/en/docs/ngx_core_module.html#include
    # for more information.
  #   include /etc/nginx/conf.d/*.conf
    server {
        listen       80 default_server;
        listen       [::]:80 default_server;
        server_name  _;
        root         /usr/share/nginx/html;
        index        index.html;
        # Load configuration files for the default server block.
        include /etc/nginx/default.d/*.conf;

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

        error_page 404 /404.html;
            location = /40x.html {
        }

        error_page 500 502 503 504 /50x.html;
            location = /50x.html {
        }
    }
include /etc/nginx/sites-enabled/*.conf;
server_names_hash_bucket_size 64;
}

mydomain1.com.conf

server {
    listen 80;
    server_name mydomain1.com www.mydomain1.com;
    location / {
        root /var/www/html/;
        index index.php;
    }
    location ~ \.php$ {
        try_files $uri =404;
        fastcgi_pass unix:/var/run/php-fpm/php-fpm.sock;
        fastcgi_index index.php;
        include fastcgi_params;
    }

}

mydomain2.com.conf

server {
    listen 80;
    server_name mydomain2.com www.mydomain2.com;
    location / {
        try_files $uri $uri/ =404;
        root /var/www/aramis;
        index index.php;
    }
    location ~ \.php$ {
        try_files $uri =404;
        fastcgi_pass unix:/var/run/php-fpm/php-fpm.sock;
        fastcgi_index index.php;
        include fastcgi_params;
    }

}

/etc/php-fm.d/www.conf

[www]
listen = /var/run/php-fpm/php-fpm.sock
listen.allowed_clients = 127.0.0.1
listen.owner = nobody
listen.group = nobody
;listen.mode = 0660
user = nginx
group = nginx
pm = dynamic
pm.max_children = 50
pm.start_servers = 5
pm.min_spare_servers = 5
pm.max_spare_servers = 35
php_admin_value[error_log] = /var/log/php-fpm/www-error.log
php_admin_flag[log_errors] = on
php_value[session.save_handler] = files
php_value[session.save_path] = /var/lib/php/session

I also tried to find php-fpm.sock but I was not successful. What I get when try to see my websites from browser is 404 Error.

3
  • You'd be better off asking on Server Fault. But don't crosspost.
    – miken32
    Feb 3, 2017 at 4:38
  • What do the NGINX access logs have? Feb 3, 2017 at 5:24
  • It just shows my tries to see my websites
    – Mahdi
    Feb 3, 2017 at 7:04

2 Answers 2

1

You have no root directive for your PHP location block. If it is the same root for all files (both static and dynamic) then move the root directive to the server block and allow the same value to be inherited by both location blocks.

server {
    ...
    root /var/www/aramis;
    index index.php;

    location / {
        try_files $uri $uri/ =404;
    }
    location ~ \.php$ {
        try_files $uri =404;
        ...
    }
}

See this document for more.

0

Your need resolve the redundance

mydomain1.com.conf

server {
    listen 80;
    root /var/www/html/; # Set as global
    server_name mydomain1.com www.mydomain1.com;
    index index.php # Set index as global
    location / {
        # index index.php; #Remove this line
    }
    location ~ \.php$ {
        try_files $uri =404;
        fastcgi_pass unix:/var/run/php-fpm/php-fpm.sock;
        fastcgi_index index.php;
        include fastcgi_params;
    }
}

myworkingfile.conf

server {
    listen      80;
    server_name  crm.coderic.net;
    root /var/www/atrk/crm.atrk.com.co/public;
    index index.php;
    location / {
        try_files $uri $uri/ =404;
    }
    location ~ \.php$ {
        try_files $uri =404;
        fastcgi_split_path_info ^(.+\.php)(/.+)$;
        fastcgi_pass 127.0.0.1:9000;
        fastcgi_index index.php;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        include fastcgi_params;
    }
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.