I have setup a latest centos 8 on the server with nginx
and i am having a multiple projects will be running at server
For example :
var/www/html/project1
var/www/html/project2
var/www/html/project3
I have configured my NGINX.conf file as below
http {
log_format main '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"';
log_format scripts '$document_root$fastcgi_script_name > $request';
access_log /var/log/nginx/access.log main;
access_log /var/log/nginx/scripts.log scripts;
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;
server {
listen 80 default_server;
listen [::]:80 default_server;
server_name _;
root /var/www/html;
# Load configuration files for the default server block.
include /etc/nginx/default.d/*.conf;
index index.php index.html index.htm;
location / {
try_files $uri /index.html index.php;
}
location ~ \.php$ {
try_files $uri /index.php =404;
fastcgi_pass unix:/var/run/php-fpm/www.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
error_page 404 /404.html;
location = /40x.html {
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
}
}
}
and server is running on the ipaddress so in server name i have just put _ as server name which will consider it localhost or ip.
But when i am running the projects
I am getting 404 Error and when i configured the script log. i found it going wrong as below
/var/log/nginx/scripts.log
/var/www/html/project1/public/404.html > GET /project1/ HTTP/1.1
/var/www/html/project2/public/404.html > GET /project2/ HTTP/1.1
Can please guide me where i am going wrong on NGINX configuration ?
This textbox defaults to using Markdown to format your answer.
You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!
Hi @kashyapwaytoweb,
The Nginx.conf file is not really meant to be used that way so it’s possible this is comming from exactly that usage.
Can you please try and create the file config file in the folder /etc/nginx/sites-available/ In there you should be able to keep the same configuration. What I mean is, you’ll still be able to keep the following
server {
listen 80;
listen [::]:80;
server_name _;
root /var/www/html;
# Load configuration files for the default server block.
include /etc/nginx/default.d/*.conf;
index index.php index.html index.htm;
location / {
try_files $uri /index.html index.php;
}
location ~ \.php$ {
try_files $uri /index.php =404;
fastcgi_pass unix:/var/run/php-fpm/www.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME
$document_root$fastcgi_script_name;
include fastcgi_params;
}
error_page 404 /404.html;
location = /40x.html {
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
}
}
Save it and try again to load the applications.
If this doesn’t work, please try adding another location to your Nginx block for each app like so :
location /project1 {
try_files $uri /index.html index.php;
}
Another thing to have in mind is to make sure you have an index.html or index.php file. If you are using any other type of file as an initial one, add it to the above line.
Don’t forget to add the symlink to the site-enabled folder after you are done
sudo ln -s /etc/nginx/sites-available/nameOfFIle /etc/nginx/sites-enabled/
Regards, KFSys
Hello there,
In addition to what has already been mentioned, I wanted to point out that CentOS Linux 8 has reached End Of Life (EOL) on December 31st, 2021.
I would strongly recommend planning either migration to another OS like Debian or Ubuntu, or upgrading to CentOS Stream.
I personally believe that the safest way to do this is to follow these steps here:
rsync for example copy over your files and migrate your databasesRegards, Alex
Get paid to write technical tutorials and select a tech-focused charity to receive a matching donation.
Full documentation for every DigitalOcean product.
The Wave has everything you need to know about building a business, from raising funding to marketing your product.
Stay up to date by signing up for DigitalOcean’s Infrastructure as a Newsletter.
New accounts only. By submitting your email you agree to our Privacy Policy
Scale up as you grow — whether you're running one virtual machine or ten thousand.
Sign up and get $200 in credit for your first 60 days with DigitalOcean.*
*This promotional offer applies to new accounts only.