Question
NGINX issue, curl work but request from the browser doesn't
Hello,
I purchased a droplet yesterday with Ubuntu 14.04x64. Here is what I have installed:
- NGINX (I followed this article: https://www.digitalocean.com/community/tutorials/how-to-set-up-nginx-server-blocks-virtual-hosts-on-ubuntu-14-04-lts)
- php and mysql (I followed this article: https://www.digitalocean.com/community/tutorials/how-to-install-linux-nginx-mysql-php-lemp-stack-on-ubuntu-14-04 and https://www.digitalocean.com/community/tutorials/how-to-install-laravel-with-an-nginx-web-server-on-ubuntu-14-04)
I opened my /etc/nginx/nginx.conf file and and changed its configuration like this:
user www-data;
worker_processes 1;
pid /run/nginx.pid;
events {
worker_connections 1024;
multi_accept on;
}
http {
##
# Basic Settings
##
sendfile on;
tcp_nopush on;
tcp_nodelay on;
#keepalive_timeout 65;
types_hash_max_size 2048;
# server_tokens off;
server_names_hash_bucket_size 64;
# server_name_in_redirect off;
include /etc/nginx/mime.types;
default_type application/octet-stream;
##
# Additional settings
##
client_body_buffer_size 10K;
client_header_buffer_size 1k;
client_max_body_size 8m;
large_client_header_buffers 2 1k;
client_body_timeout 12;
client_header_timeout 12;
keepalive_timeout 15;
send_timeout 10;
open_file_cache max=5000 inactive=20s;
open_file_cache_valid 30s;
open_file_cache_min_uses 2;
open_file_cache_errors on;
##
# Logging Settings
##
access_log /var/log/nginx/access.log;
#access_log off;
error_log /var/log/nginx/error.log;
#error_log /var/log/nginx/error.log crit;
##
# Gzip Settings
##
gzip on;
gzip_disable "msie6";
# gzip_vary on;
# gzip_proxied any;
gzip_proxied expired no-cache no-store private auth;
gzip_comp_level 2;
gzip_min_length 1000;
gzip_buffers 4 32k;
# gzip_http_version 1.1;
gzip_types text/plain text/css application/json application/x-javascript text/xml application/xml application/xml+rss text/javascript;
##
# nginx-naxsi config
##
# Uncomment it if you installed nginx-naxsi
##
#include /etc/nginx/naxsi_core.rules;
##
# nginx-passenger config
##
# Uncomment it if you installed nginx-passenger
##
#passenger_root /usr;
#passenger_ruby /usr/bin/ruby;
##
# Virtual Host Configs
##
include /etc/nginx/conf.d/*.conf;
include /etc/nginx/sites-enabled/*;
}
#mail {
# # See sample authentication script at:
# # http://wiki.nginx.org/ImapAuthenticateWithApachePhpScript
#
# # auth_http localhost/auth.php;
# # pop3_capabilities "TOP" "USER";
# # imap_capabilities "IMAP4rev1" "UIDPLUS";
#
# server {
# listen localhost:110;
# protocol pop3;
# proxy on;
# }
#
# server {
# listen localhost:143;
# protocol imap;
# proxy on;
# }
#}
I also opened /sites-available and i created two files: web1 and web2. The content of we1 is:
server {
listen 80 default_server;
listen [::]:80 ipv6only=on default_server;
root /var/www/web1;
index index.php index.html index.htm;
server_name web1.com;
location / {
try_files $uri $uri/ /index.php?$query_string;
}
location ~ \.php$ {
try_files $uri /index.php =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;
}
}
The content of web2 is:
server {
listen 80;
listen [::]:80;
root /var/www/web2;
index index.php index.html index.htm;
server_name web2.com;
location / {
try_files $uri $uri/ /index.php?$query_string;
}
location ~ \.php$ {
try_files $uri /index.php =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;
}
}
Also, the directories: /var/www/web1 and /var/www/web2 have index.html files. The domains web1.com and web2.com have DNS records to the servers of Digital Ocean and also they have A records pointing to the droplet.
Also I have created soft link to /etc/nginx/sites-enabled. Here are they:
web1 -> /etc/nginx/sites-available/web1
web2 -> /etc/nginx/sites-available/web2
I restarted nginx: service nginx reload
And here is the issue:
- When I try to access web1.com from my web browser it returns my a message “This webpage is not available”.
- When I execute a curl request from another server:
curl web1.com
I get the expected content which is in the index.html file.
I searched a lot in Google and I can’t anyone with identical issue. Can anyone help me please?
Ou, and before I forget, I checked port 80
netstat -tulpn | grep :80
and here is what I get:
tcp 0 0 0.0.0.0:80 0.0.0.0:* LISTEN 6001/nginx
tcp6 0 0 :::80 :::* LISTEN 6001/nginx
These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.
×