Nginx configuration

Does anyone have a nginx configuration with index.php removed? For me, after setting restful_urls to On, the links don’t work and the styles don’t load.

1 Like

Hi, you can try this one. Its from my working configuration.

server {
	server_name example.com www.example.com;
	
	root /var/www/journalname/public_html;
	index index.html index.php  index.htm;

client_max_body_size 128M;
	
if ($host = www.example.com) {
    return 301 https://example.com$request_uri;
} 
	
	if ($host != "example.com") {
			return 444;
	}
	
location / {
    try_files $uri $uri/ /index.php;
		
		
		rewrite ^/index/(.*)$ /index.php/index/$1;
		rewrite ^/index$ / redirect;
		rewrite ^/(.*)$ /index.php/journalname/$1;
}
	
	location ~ ^\/journalname {
		rewrite ^\/journalname/api/(.*)$ /index.php/journalname/api/$1;
	}
	
location ~* /\. {
    deny all;
}
	
	location ~ ^/(cache|classes|controllers|dbscripts|docs|js|lib|locale|node_modules|pages|plugins|public|registry|styles|templates|tests|tools)/ {}
	

	location = /favicon.ico { access_log off; log_not_found off; }
	location = /robots.txt  { access_log off; log_not_found off; }

	location ~ ^(.+\.php)(.*)$ {
    set $path_info $fastcgi_path_info;
    fastcgi_split_path_info ^(.+\.php)(.*)$;
    fastcgi_param PATH_INFO $path_info;
    fastcgi_param PATH_TRANSLATED $document_root$path_info;

    if (!-f $document_root$fastcgi_script_name) {
        return 404;
    }
    include fastcgi_params;

		fastcgi_read_timeout 500000;	
    fastcgi_pass unix:/var/run/php/php7.3-fpm.sock;
    fastcgi_index index.php;
    fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
		
}
}

Also in config must be:

base_url[index] = https://example.com/index
base_url[journalname] = https://example.com
2 Likes