0

I am using CentOS Linux release 7.6.1810 (Core), NGINX 1.12.2, VPS has ip 103.48.111.34

I have two domains: foo.com and bar.com . Domain control at GoDaddy.

http://foo.com use ASP.NET Core, can access at http://localhost:5000

http://bar.com use Wordpress version 5, put at /etc/home/bar PHP 7 is work ok.

The content of /etc/nginx/nginx.conf is

error_log /var/log/nginx/error.log;
pid /run/nginx.pid;

# Load dynamic modules. See /usr/share/nginx/README.dynamic.
include /usr/share/nginx/modules/*.conf;

events {
    worker_connections 1024;
}

http {
    log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
                      '$status $body_bytes_sent "$http_referer" '
                      '"$http_user_agent" "$http_x_forwarded_for"';

    access_log  /var/log/nginx/access.log  main;

    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;
    include /etc/nginx/sites-enabled/*.conf;
    server_names_hash_bucket_size 64;


# Settings for a TLS enabled server.
#
#    server {
#        listen       443 ssl http2 default_server;
#        listen       [::]:443 ssl http2 default_server;
#        server_name  _;
#        root         /usr/share/nginx/html;
#
#        ssl_certificate "/etc/pki/nginx/server.crt";
#        ssl_certificate_key "/etc/pki/nginx/private/server.key";
#        ssl_session_cache shared:SSL:1m;
#        ssl_session_timeout  10m;
#        ssl_ciphers HIGH:!aNULL:!MD5;
#        ssl_prefer_server_ciphers on;
#
#        # Load configuration files for the default server block.
#        include /etc/nginx/default.d/*.conf;
#
#        location / {
#        }
#
#        error_page 404 /404.html;
#            location = /40x.html {
#        }
#
#        error_page 500 502 503 504 /50x.html;
#            location = /50x.html {
#        }
#    }

}

The content of /etc/nginx/sites-available/bar.com is

server {
        listen 80;
        listen [::]:80;

        root /home/bar/;
        index index.html index.htm index.php;

        server_name bar.com www.bar.com;

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

then

sudo ln -s /etc/nginx/sites-available/bar.com /etc/nginx/sites-enabled/
nginx -t
systemctl restart nginx
service nginx status

Then I edit file /etc/hosts . The content of /etc/nginx/nginx.conf is

103.48.111.34 bar.com www.bar.com
103.48.111.34 foo.vn www.foo.vn

I am using client Windows 10 pro, I run ipconfig /flushdns and clear web browser cache. Try to access http://foo.com and http://bar.com , result: http://foo.com work ok, http://bar.com always point to the content of http://foo.com

How to config NGINX server block work with 1 site use port, and 1 site use directory, in same VPS?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.