安裝各種伺服器軟體 nginx 安裝完成之後,直接使用ip地址訪問伺服器,就可以看到nginx的預設歡迎頁面了。 如果安裝報錯比如80埠占用,說明此前安裝了其它網路伺服器,建議全都關掉再安裝,並且讓nginx獨占80埠作為反向代理伺服器 安裝完成之後配置反向代理,使用whereis nginx命 ...
安裝各種伺服器軟體
nginx
sudo apt-get install nginx
安裝完成之後,直接使用ip地址訪問伺服器,就可以看到nginx的預設歡迎頁面了。
如果安裝報錯比如80埠占用,說明此前安裝了其它網路伺服器,建議全都關掉再安裝,並且讓nginx獨占80埠作為反向代理伺服器
安裝完成之後配置反向代理,使用whereis nginx命令找到配置文件所在文件夾,找到nginx.conf後進行如下修改(記得備份該文件)
$ whereis nginx
# 顯示nginx相關目錄,挨個看看找到nginx.conf的位置,不同的系統可能不一樣
$ cd /etc/nginx # 我的nginx配置在這裡,不同版本會有區別
$ sudo cp nginx.conf nginx.conf.bk # 備份
$ sudo vi nginx.conf
我的配置如下
############### 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; # 監聽80埠
# server_name milkyship.cn www.milkyship.cn;
access_log /data/wwwlogs/nginx/access.log combined; # 日誌文件位置
root /data/wwwroot; # 網頁根目錄
index index.html index.php index.jsp; # 主頁文件
#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; # 轉發Apache伺服器
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; # 轉發TomCat伺服器
# include proxy.conf;
}
}
##
# Virtual Host Configs
##
include /etc/nginx/conf.d/*.conf;
include /etc/nginx/sites-enabled/*;
}
最後使用
$ service nginx restart
重啟nginx伺服器,如果報錯,檢查剛剛設置過程中有沒有拼寫錯誤,設置的網站根目錄有沒有建立好
apache
sudo apt-get install apache2
!!!下方操作前記得備份!!!
安裝完成後在 /etc/apache2/ports.conf 中修改所有的80到8090,443到8091以避開nginx監聽埠
再在 /etc/apache2/sites-enabled/000-default.conf 中修改DocumentRoot到個人的網站根目錄
最後使用
$ service apache2 restart
重啟apache伺服器,如果報錯,檢查剛剛設置過程中有沒有拼寫錯誤,設置的網站根目錄有沒有建立好
tomcat
$ sudo apt-get install tomcat8
$ service tomcat8 start
這裡沒什麼配置要改,前面該改的都弄好了
現在伺服器上有3個web伺服器在運行,nginx監聽80埠做前臺反向代理,apache監聽8090埠做php伺服器,tomcat監聽8080埠做java伺服器,並且使用的時候使用nginx正則匹配url分配流量到正確的伺服器上(這個還需要後面進一步設置)
ftp
$ sudo apt-get install vsftpd
$ sudo vi /etc/vsftpd.conf # 進入配置
文件尾追加:
#配置ftp伺服器的上傳下載文件所在的目錄。
local_root=/home/ftpfile
如果想要使用管理員許可權登入以訪問非ftp指定目錄,在配置文件中找到如下屬性,如下修改:
chroot_local_user=YES
chroot_list_enable=YES
# (default follows) 允許chroot_list文件中配置的用戶登錄此ftp伺服器。
chroot_list_file=/etc/vsftpd.chroot_list # 本行需要新增
隨後配置允許管理員許可權登入的用戶,每行寫入一個允許管理員許可權登入的用戶的用戶名
$ sudo vi /etc/vsftpd.chroot_list
最後重啟ftp服務
$ service vsftpd restart
此時便可以使用ftp工具登錄伺服器進行文件傳輸