0

Every nginx config guide I find is about setting up the server for, say, example.com. But I don't have a domain name, and I want to set up a local DNS, something like localhost in Windows with Apache that comes with XAMPP. I want to create two ports, which is I believe server blocks in nginx. One of the ports is for api, one of the ports is for the frontend. I have created two files:

/etc/nginx/conf.d/chubak.conf:

server {
        listen 85;
        server_name chubak.com;
        access_log /srv/logs/vue.access.log;
        error_log /srv/logs/vue.error.log;
        gzip_static on;
# root /srv/default;
        root /var/www/chubak.com/html;
        index index.html;
        location / {
                add_header 'Access-Control-Allow-Origin' '*';
                try_files $uri $uri/ /index.html;
        }

And /etc/nginx/conf.d/api.chubak.conf:

server {
        listen 180;
        server_name api.chubak.com;
        access_log /var/www/api.chubak.com/logs/api.access.log;
        error_log /var/www/api.chubak.com/logs/api.error.log;
        root /var/www/api.chubak.com/html;
        index index.php index.html;
        client_max_body_size 128M;
        location / {
            try_files $uri $uri/ /index.php?_url=$uri&$args;
        }
        location ~ \.php$ {
            include /etc/nginx/fastcgi.conf;
            fastcgi_split_path_info       ^(.+\.php)(/.+)$;
            fastcgi_param PATH_INFO       $fastcgi_path_info;
            fastcgi_param PATH_TRANSLATED $document_root$fastcgi_path_info;
            fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
            try_files $uri =404;
            fastcgi_pass unix:/var/run/php/php7.2-fpm.sock;
            fastcgi_read_timeout 600;
            fastcgi_intercept_errors on;
            gzip off;
            fastcgi_index   index.php;
        }

And I've created index.html files in the /var/www/site/html folder, but I don't know how to access them. As I said, the tutorials always assume that you have a domain name pointed to your server.

0

The localhost file for debian-based systems is /etc/hosts. Just add a line after the final 127.0.0.1 line with something like this (use the IP address most appropriate):

127.0.0.1    chubak.com
127.0.0.1    api.chubak.com

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.