Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

correct configuration for nginx to localhost?

I just installed nginx and php fastcgi about an hour ago, and after reading examples of a quick starting configuration, and the nginx documentation etc, I just cant get it to work.

No matter what I change or try, I always only get the "Welcome to Nginx!" screen on "localhost/..." - I cant even call a simple index.html

My config:

(the stuff in the comments is what I tried out)

// default nginx stuff (unchanged)  server {     #listen 80 default_server;     #listen 80 default;     listen 80;      #server_name localhost;     #server_name _;      #access_log /var/log/nginx/board.access_log;     #error_log /var/log/nginx/board.error_log;      #root /var/www/board;     #root /var/www/board/public/;     root /var/www/board/public;      #index index.html;     index index.html index.htm index.php; } 

If I understand it right, this should be the easiest setup, right? just define listen 80; and index index.html; but I just cant get it to work

The file /var/www/board/public/index.html exists and has content

Before I waste 2 more hours trying out something, can someone of you give it a quick watch and tell me what I'm doing wrong? Thanks.

like image 529
Katai Avatar asked Jun 16 '12 08:06

Katai


People also ask

How do I know if nginx config is correct?

Through a simple command you can verify the status of the Nginx configuration file: $ sudo systemctl config nginx The output will show if the configuration file is correct or, if it is not, it will show the file and the line where the problem is.

What is the default nginx config?

By default, the configuration file is named nginx. conf and placed in the directory /usr/local/nginx/conf , /etc/nginx , or /usr/local/etc/nginx .

How do I find my nginx config?

To test the Nginx configuration, run the following command. You can test the Nginx configuration, dump it and exit using the -T flag as shown. nginx: the configuration file /etc/nginx/nginx. conf syntax is ok nginx: configuration file /etc/nginx/nginx.


1 Answers

Fundamentally you hadn't declare location which is what nginx uses to bind URL with resources.

 server {             listen       80;             server_name  localhost;              access_log  logs/localhost.access.log  main;              location / {                 root /var/www/board/public;                 index index.html index.htm index.php;             }        } 
like image 55
Samy Vilar Avatar answered Sep 24 '22 13:09

Samy Vilar