e-smartsolution » Smartsolution

Smartsolution

How to keep ng serve, angular running on production server on ubuntu using nginx as website server

2019-10-19 15:39:46 websitedeveloper

How to keep ng serve, angular running on production server on ubuntu using nginx as website server

Solution 1

$ sh -c ng serve -w –port 1355 –live-reload 1356 –aot –env=prod “/home/ubuntu/project/ukgoodbye/”

Solution 2

$ forever start node_modules/@angular/cli/bin/ng serve -w –port 1355 –live-reload 1356 –aot –env=prod “/home/ubuntu/project/ukgoodbye/”


sudo forever start node_modules/@angular/cli/bin/ng serve -w --port 1355 --live-reload 1356 --aot --env=prod 
warn:    --minUptime not set. Defaulting to: 1000ms
warn:    --spinSleepTime not set. Your script will exit if it does not stay up for at least 1000ms
info:    Forever processing file: node_modules/@angular/cli/bin/ng

Check the log:
$ nano -v /home/ubuntu/.forever/dfyn.log

sudo forever start –watch app.js that will run sails lift

Posted in: AngularNode jsWebsite developerTagged in: foreverng serve Read more... 0 comments

How to check if Nginx is running on linux, ubuntu

2019-10-19 15:31:01 websitedeveloper

How to check if Nginx is running on linux, ubuntu

On linux ubuntu, you can use those commands to verify Ngnix
Sudo service nginx status and to start or stop
Sudo service nginx start Sudo service nginx stop


ubuntu@ip-127-0-0-1:/$ sudo service nginx status
● nginx.service - A high performance web server and a reverse proxy server
   Loaded: loaded (/lib/systemd/system/nginx.service; enabled; vendor preset: enabled)
  Drop-In: /etc/systemd/system/nginx.service.d
           └─override.conf
   Active: inactive (dead) since Fri 2019-10-18 20:54:21 UTC; 11h ago
  Process: 19623 ExecStop=/sbin/start-stop-daemon --quiet --stop --retry QUIT/5 --pidf
  Process: 19378 ExecReload=/usr/sbin/nginx -g daemon on; master_process on; -s reload
  Process: 19332 ExecStartPost=/bin/sleep 0.1 (code=exited, status=0/SUCCESS)
  Process: 19327 ExecStart=/usr/sbin/nginx -g daemon on; master_process on; (code=exit
  Process: 19322 ExecStartPre=/usr/sbin/nginx -t -q -g daemon on; master_process on; (
 Main PID: 19329 (code=exited, status=0/SUCCESS)
Oct 18 20:02:40 ip-172-31-38-119 systemd[1]: Starting A high performance web server an
Oct 18 20:02:40 ip-172-31-38-119 systemd[1]: Started A high performance web server and
Oct 18 20:16:51 ip-172-31-38-119 systemd[1]: Reloading A high performance web server a
Oct 18 20:16:51 ip-172-31-38-119 systemd[1]: Reloaded A high performance web server an
Oct 18 20:54:21 ip-172-31-38-119 systemd[1]: Stopping A high performance web server an
Oct 18 20:54:21 ip-172-31-38-119 systemd[1]: Stopped A high performance web server and

Read more... 0 comments

How to run mongodb on linux,ubuntu as process

2019-10-19 07:56:44 websitedeveloper

How to run mongodb on linux,ubuntu as process

Supposed that mongodb is installed and configured, and now you want to Start mongod as a Daemon:


ubuntu@ip-127-0-0-1:/var/lib/mongodb$ sudo mongod --fork --logpath /var/log/mongodb.log --dbpath /var/lib/mongodb
about to fork child process, waiting until server is ready for connections.
forked process: 21293
child process started successfully, parent exiting
ubuntu@ip-127-0-0-1:/var/lib/mongodb$ 

Now, how to test if mongodb has started really as daemon;


ubuntu@ip-127-0-0-1:/var/lib/mongodb$ mongo
MongoDB shell version v3.4.9
connecting to: mongodb://127.0.0.1:27017
MongoDB server version: 3.4.9
Server has startup warnings: 
2019-10-19T07:49:38.302+0000 I STORAGE  [initandlisten] 
2019-10-19T07:49:38.303+0000 I STORAGE  [initandlisten] ** WARNING: Using the XFS filesystem is strongly recommended with the WiredTiger storage engine
2019-10-19T07:49:38.303+0000 I STORAGE  [initandlisten] **          See http://dochub.mongodb.org/core/prodnotes-filesystem
2019-10-19T07:49:38.571+0000 I CONTROL  [initandlisten] 
2019-10-19T07:49:38.571+0000 I CONTROL  [initandlisten] ** WARNING: Access control is not enabled for the database.
2019-10-19T07:49:38.571+0000 I CONTROL  [initandlisten] **          Read and write access to data and configuration is unrestricted.
2019-10-19T07:49:38.571+0000 I CONTROL  [initandlisten] ** WARNING: You are running this process as the root user, which is not recommended.
2019-10-19T07:49:38.571+0000 I CONTROL  [initandlisten] 
2019-10-19T07:49:38.571+0000 I CONTROL  [initandlisten] 
2019-10-19T07:49:38.571+0000 I CONTROL  [initandlisten] ** WARNING: /sys/kernel/mm/transparent_hugepage/enabled is 'always'.
2019-10-19T07:49:38.571+0000 I CONTROL  [initandlisten] **        We suggest setting it to 'never'
2019-10-19T07:49:38.571+0000 I CONTROL  [initandlisten] 
2019-10-19T07:49:38.571+0000 I CONTROL  [initandlisten] ** WARNING: /sys/kernel/mm/transparent_hugepage/defrag is 'always'.
2019-10-19T07:49:38.571+0000 I CONTROL  [initandlisten] **        We suggest setting it to 'never'
2019-10-19T07:49:38.571+0000 I CONTROL  [initandlisten] 
> show dbs
admin      0.000GB
UKgoodbye  0.002GB
local      0.000GB
> 

Mongodb is ready!

Posted in: AngularDatabaseMongoDBWebsite developer Read more... 0 comments

Nginx configuration location on AWS ubuntu, /etc/nginx/nginx.conf

2019-10-18 14:34:29 websitedeveloper

Nginx configuration location on AWS ubuntu, /etc/nginx/nginx.conf

Here an example of nginx.conf


user www-data;
worker_processes auto;
pid /run/nginx.pid;

events {
        worker_connections 768;
        # 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;

        ##
        # SSL Settings
        ##

        ssl_protocols TLSv1 TLSv1.1 TLSv1.2; # Dropping SSLv3, ref: POODLE
          ssl_prefer_server_ciphers on;

        ##
        # Logging Settings
        ##

        access_log /var/log/nginx/access.log;
        error_log /var/log/nginx/error.log;

        ##
        # Gzip Settings
        ##

        gzip on;
        gzip_disable "msie6";

         gzip_vary on;
          gzip_proxied any;
         gzip_comp_level 9;
         gzip_buffers 16 8k;
         gzip_http_version 1.1;
         gzip_types text/plain text/css application/json application/javascript text/xml application/xml application/xml+rss text$

        ##
        # 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;
#       }
#}

It says that it include sites-enabled/*. cd /etc/nginx/sites-enabled/ to find out, www.ukgoodbye.co.uk

Content of the enabled site:


....
##
# You should look at the following URL's in order to grasp a solid understanding
# of Nginx configuration files in order to fully unleash the power of Nginx.
# http://wiki.nginx.org/Pitfalls
# http://wiki.nginx.org/QuickStart
# http://wiki.nginx.org/Configuration
#
# Generally, you will want to move this file somewhere, and start with a clean
# file but keep this around for reference. Or just disable in sites-enabled.
#
# Please see /usr/share/doc/nginx-doc/examples/ for more detailed examples.
##

# Default server configuration
#
server {
        # listen 80 default_server;
        # listen [::]:80 default_server;

        # SSL configuration
        #
        listen 443;
        listen [::]:443;

        ssl on;
        ssl_certificate /etc/nginx/ssl/ssl_bundle.crt;
        ssl_certificate_key /etc/nginx/ssl/ukgoodbye_com.key;

        ssl_dhparam /etc/nginx/ssl/dhparam.pem;

        ssl_protocols TLSv1 TLSv1.1 TLSv1.2;

        #
        #
        # Note: You should disable gzip for SSL traffic.
        # See: https://bugs.debian.org/773332
        #
        # Read up on ssl_ciphers to ensure a secure configuration.
        # See: https://bugs.debian.org/765782
        #
        # Self signed certs generated by the ssl-cert package
        # Don't use them in a production server!
        #
        # include snippets/snakeoil.conf;

        root /var/www/html;

        # Add index.php to the list if you are using PHP
        index index.html index.htm index.nginx-debian.html;

        server_name www.ukgoodbye.co.uk;


        location / {
                #rewrite ^/ukgoodbye(.*) $1 break;
                #add_header "Access-Control-Allow-Origin" "*, *";
                proxy_pass http://127.0.0.1:1355;
        }
        location /ukgoodbye-services/ {
                rewrite ^/ukgoodbye-services(.*) $1 break;
                #add_header "Access-Control-Allow-Origin" "*, *";
                proxy_pass http://127.0.0.1:1337;
        }

#       location / {
                # First attempt to serve request as file, then
                # as directory, then fall back to displaying a 404.
#               try_files $uri $uri/ =404;
#       }

        # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
        #
        #location ~ \.php$ {
        #       include snippets/fastcgi-php.conf;
        #
        #       # With php7.0-cgi alone:
        #       fastcgi_pass 127.0.0.1:9000;
        #       # With php7.0-fpm:
        #       fastcgi_pass unix:/run/php/php7.0-fpm.sock;
        #}

        # deny access to .htaccess files, if Apache's document root
        # concurs with nginx's one
        #
        #location ~ /\.ht {
        #       deny all;
        #}
}


# Virtual Host configuration for example.com
#
# You can move that to a different file under sites-available/ and symlink that
# to sites-enabled/ to enable it.
#
server {
        listen 80;
        listen [::]:80;
        # Redirect all HTTP requests to HTTPS with a 301 Moved Permanently response.
        return 301 https://$host$request_uri;
        server_name www.ukgoodbye.co.uk;

#       root /var/www/example.com;
#       index index.html;
#
#       location / {
#               try_files $uri $uri/ =404;
#       }
}
Posted in: AngularDatabaseMongoDBNode jsSails jsWebsite developer Read more... 0 comments

nginx/1.10.3 (Ubuntu) server error 502 Bad Gateway, solution

2019-10-17 07:53:37 websitedeveloper

nginx/1.10.3 (Ubuntu) server error 502 Bad Gateway, solution

Nginx won’t work after rebooting the server

First at all, check the configuration of Nginx, by typing nginx -t


ubuntu@ip-127-0-0-1:/$ nginx -t
nginx: [alert] could not open error log file: open() "/var/log/nginx/error.log" failed (13: Permission denied)
2019/10/17 07:45:33 [warn] 2671#2671: the "user" directive makes sense only if the master process runs with super-user privileges, ignored in /etc/nginx/nginx.conf:1
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
2019/10/17 07:45:33 [emerg] 2671#2671: open() "/run/nginx.pid" failed (13: Permission denied)

And double check the nginx configuration…in case http://127.0.0.1:1337 is where sails js should be running, the solution is load sails js


	# Add index.php to the list if you are using PHP
	index index.html index.htm index.nginx-debian.html;

	server_name www.ukgoodbye.co.uk;
	

	location / {
                #rewrite ^/ukgoodbye(.*) $1 break;
                #add_header "Access-Control-Allow-Origin" "*, *";
                proxy_pass http://127.0.0.1:1355;
        }
        location /ukgoodbye-services/ {
                rewrite ^/ukgoodbye-services(.*) $1 break;
                #add_header "Access-Control-Allow-Origin" "*, *";
                proxy_pass http://127.0.0.1:1337;
        }



Posted in: NginxWeb developersWeb server Read more... 0 comments