When you buy a new ubuntu server

Install various server software

nginx

sudo apt-get install nginx

Once the installation is complete, use the ip address directly to access the server and you will see the default welcome page for nginx.

If installation errors, such as port 80 occupancy, indicate that other network servers have been installed before, it is recommended that you shut down and reinstall them all, and let nginx exclusive port 80 act as a reverse proxy server

Configure the reverse proxy after installation, use the whereis nginx command to find the folder where the configuration file is located, and make the following modifications after finding nginx.conf (remember to back up the file)

$ whereis nginx
# Show the directories related to nginx, look one by one to find the location of nginx.conf, different systems may be different
$ cd /etc/nginx  # My nginx configuration is here, different versions will differ
$ sudo cp nginx.conf nginx.conf.bk  # backups
$ sudo vi nginx.conf

My configuration is as follows

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

events {
	use epoll;
	worker_connections 51200;
	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 /data/wwwlogs/nginx/access.log;
	error_log /data/wwwlogs/nginx/error.log;

	##
	# Gzip Settings
	##

	gzip on;
	gzip_disable "msie6";

	gzip_vary on;
	gzip_proxied any;
	gzip_comp_level 6;
	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/javascript;

############# basic web #############

	server {
		listen 80;  # Listen on port 80
		# server_name milkyship.cn  www.milkyship.cn;
		access_log /data/wwwlogs/nginx/access.log combined;  # Log file location
		root /data/wwwroot;  # Page Root Directory
		index index.html index.php index.jsp; # Home Page File

		#error_page 404 /404.html;
		#error_page 502 /502.html;

		location /nginx_status {
			stub_status on;
			access_log off;
			allow 127.0.0.1;
			deny all;
		}

		location ~ .*\.(gif|jpg|jpeg|png|bmp|mp3|wma|wmv|swf|flv|mp4|mkv|avi|ico|txt|pdf|rar|zip|7z|gz)$ {
			expires 30d;
			access_log off;
		}

		location ~ .*\.(js|css)?$ {
			expires 7d;
			access_log off;
		}

		location ~ .*\.[(php)(html)(htm)]$ {
			proxy_pass http://127.0.0.1:8090; #Forward Apache Server
			proxy_next_upstream http_502 http_504 error timeout invalid_header;
			proxy_set_header Host $host;
			proxy_set_header X-Real-IP $remote_addr;
			proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; 
		}

		location ~ ^/(\.user.ini|\.ht|\.git|\.svn|\.project|LICENSE|README.md) {
			deny all;
		}

		location ~.*$ {
      			proxy_pass http://127.0.0.1:8080; #Forward TomCat Server
			# include proxy.conf;
		}
	}



	##
	# Virtual Host Configs
	##

	include /etc/nginx/conf.d/*.conf;
	include /etc/nginx/sites-enabled/*;
}

Last used

$ service nginx restart

Restart the nginx server, if an error occurs, check for spelling errors during the setup process, and set up the site root directory

apache

sudo apt-get install apache2

!!!Backup before operation below!!!

Modify all 80 to 8090, 443 to 8091 in/etc/apache2/ports.conf after installation to avoid nginx listening port

Modify the DocumentRoot to your personal site root directory in / etc/apache2/sites-enabled/000-default.conf

Last used

$ service apache2 restart

Restart the apache server, check for spelling errors in the setup process, and set up the site root directory

tomcat

$ sudo apt-get install tomcat8
$ service tomcat8 start

There's nothing to change here, everything else is done

Now there are three web servers running on the server, nginx listens on port 80 as a foreground reverse proxy, apache listens on port 8090 as a php server, tomcat listens on port 8080 as a java server, and uses nginx to regularly match URLs to allocate traffic to the correct server (this requires further setup later)

ftp

$ sudo apt-get install vsftpd
$ sudo vi /etc/vsftpd.conf  # Enter Configuration

End of file appended:

#Configure the directory where the ftp server uploads and downloads files.
local_root=/home/ftpfile

If you want to log in with administrator privileges to access a directory other than the ftp specified, find the following properties in the configuration file, modify as follows:

chroot_local_user=YES
chroot_list_enable=YES
# (default follow) Allows users configured in the chroot_list file to log on to this ftp server.
chroot_list_file=/etc/vsftpd.chroot_list # This line needs to be added

Subsequently, configure users to allow administrator rights to log in, writing one user name per line for users to allow administrator rights to log in

$ sudo vi /etc/vsftpd.chroot_list

Last restart ftp service

$ service vsftpd restart

You can then log in to the server using the ftp tool for file transfer

Tags: Linux Nginx sudo ftp vsftpd

Posted on Mon, 11 May 2020 20:53:43 -0400 by WeAnswer.IT