Welcome! Log In Create A New Profile

Advanced

404 error for php redirects after moving server info from nginx.conf to conf.d/site.conf

Posted by xnobodyx 
environment: centos 8, nginx 1.14.1, php-fpm 7.2.11

set up a php web application in /usr/share/nginx/html/webapp with server details in /etc/nginx/nginx.conf. everything seemed to be working fine. now i'm trying to move the configuration to a seperate site.conf file in /etc/nginx/conf.d.

/etc/nginx/nginx.conf remains unchanged except i commented out the server settings.

/etc/nginx/conf.d/site.conf now contains the server section copied from nginx.conf. i did change the listening port from 80 to 7070.

reloaded nginx and the new configuration works fine for the nginx test page, a php info test page in /usr/share/nginx/html, and i can login and use a phpmyadmin instance which is a subdirectory of /usr/share/nginx/html.

when i try to access the web application index.php appears to load as the uri redirects to a new login uri, however nginx returns a 404 error. on a browser which logged into the webapp under the old configuration, i am brought to the main page of the web app. however trying to navigate to any links on the page return a 404 error (i don't believe this is a cached page, held down shift and reloaded in firefox, but i could be wrong).

by removing the new conf file, restoring the old nginx.conf file, and restarting nginx, the webapp works fine again. also, if i change the listening port in nginx.conf and reload nginx, the webapp works fine.

any help is greatly appreciated.

here is the site.conf file:

server {
listen 7070 default_server;
listen [::]:7070 default_server;
server_name _;
root /usr/share/nginx/html;

location / {
}

# phpMyAdmin:
location /phpmyadmin {
root /usr/share/nginx/html;
index index.php;
}

# webapp:
location /webapp {
root /usr/share/nginx/html;
index index.php;
}

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

error_page 500 502 503 504 /50x.html;
location = /50x.html {
}

location ~ \.php$ {
try_files $uri =404;
fastcgi_pass unix:/run/php-fpm/www.sock;
fastcgi_index index.php;
client_max_body_size 2000M;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param SCRIPT_NAME $fastcgi_script_name;
fastcgi_param PATH_INFO $fastcgi_path_info;
fastcgi_split_path_info ^(.+\.php)(/.+)$;
include fastcgi_params;
}
}

and the nginx.conf file, when trying to use site.conf:

# For more information on configuration, see:
# * Official English Documentation: http://nginx.org/en/docs/
# * Official Russian Documentation: http://nginx.org/ru/docs/
user nginx;
worker_processes auto;
error_log /var/log/nginx/error.log;
pid /run/nginx.pid;

# Load dynamic modules. See /usr/share/doc/nginx/README.dynamic.
include /usr/share/nginx/modules/*.conf;

events {
worker_connections 1024;
}

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;

include /etc/nginx/mime.types;
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;
}
it looks like changing

location ~ \.php$ {

to

location ~* \.php {

did the trick.
that actually was just fixing the landing page...all the links were broken.

it turns out i accidentally pulled

# Load configuration files for the default server block.
include /etc/nginx/default.d/*.conf;

out of the server conf. putting it back in with the original location ~ \.php$ { fixed everything
Sorry, only registered users may post in this forum.

Click here to login

Online Users

Guests: 80
Record Number of Users: 6 on February 13, 2018
Record Number of Guests: 421 on December 02, 2018
Powered by nginx      Powered by FreeBSD      PHP Powered      Powered by MariaDB      ipv6 ready