简体   繁体   中英

How to setup nginx configuration?

I have been trying to figure out how to point the server to my static page that i store it up somewhere in my cloud server. Also, i am using NodeJs as my backend.

My old problem: It's not point to my myProjectX index.html instead it points to the Nginx default web page "Welcome to Nginx!". I cannot figure out why ;/

Update

My new problem: After this new configuration that i did, it points me to a 404 page instead of pointing to my index.html

Also, in the line 20, it gives me an error of duplicate "/" when i run sudo nginx -t for debugging purpose

`nginx: [emerg] duplicate location "/" in /etc/nginx/sites-enabled/default:20 `

here's my Nginx configuration file...

 server { listen 80 default_server; listen [::]:80 default_server ipv6only=on; server_name www.andii90s.com; root /home/andy/www/myProjectX/app; index index.html index.htm; location / { proxy_pass http://10.137.10.140:8080; proxy_http_version 1.1; proxy_set_header Upgrade $http_upgrade; proxy_set_header Connection 'upgrade'; proxy_set_header Host $host; proxy_cache_bypass $http_upgrade; } location / { #Line 20 try_files $uri $uri/ =404; } error_page 404 /404.html; error_page 500 502 503 504 /50x.html; location = /50x.html { root /home/andy/www/myProjectX/app; } } 

First of all, restart your NGINX service

service nginx restart

If this didn't do the trick, Also check /etc/nginx/sites-available/ if you're using the default, if you created a new one it must be available in /etc/nginx/sites-enabled/

sudo ln -s /etc/nginx/sites-available/yourconfig /etc/nginx/sites-enabled/

If you want to run a website:

server {
listen 80 default_server;
listen [::]:80 default_server ipv6only=on;

root /home/andy/www/myProjectX/app;
index index.php index.html index.htm;

server_name myUrl;

location / {
    try_files $uri $uri/ =404;
}

error_page 404 /404.html;
error_page 500 502 503 504 /50x.html;
location = /50x.html {
    root /home/andy/www/myProjectX/app;
}

And, if you want to enable PHP just add this to your config file:

location ~ \.php$ {
    try_files $uri =404;
    fastcgi_split_path_info ^(.+\.php)(/.+)$;
    fastcgi_pass unix:/var/run/php5-fpm.sock;
    fastcgi_index index.php;
    fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
    include fastcgi_params;
}

If you want to use NGINX as a proxy for example a Node.js application use this:

server {
listen 80;
server_name example.com;

location / {
    proxy_pass http://hereip:8080;
    proxy_http_version 1.1;
    proxy_set_header Upgrade $http_upgrade;
    proxy_set_header Connection 'upgrade';
    proxy_set_header Host $host;
    proxy_cache_bypass $http_upgrade;
}

This will make your application accessible on your root domain, for example: example.com. ;)

refer this blog http://caffeinecodes.blogspot.in/2017/02/nginx-settings.html

server {
  listen 80;
  server_name test.com;
  location = /favicon.ico { access_log off; log_not_found off; }
  location /static/ {
      alias /Users/Afxal/workspace/test_project/static/;
  }
  location / {
      proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
      proxy_set_header Host $http_host;
      proxy_redirect off;
      proxy_pass http://127.0.0.1:8000;
  }
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM