这里用的工具是vagrant 1.8.7,VirtualBox 5.0.40, CentOS 7.4 (Minimal)
1.root的密码需要设置为vagrant
2.创建用户vagrant时将vagrant设置成为管理员,这样就可以将vagrant加入到wheel组中了,vagrant的密码也是vagrant

vi /etc/sysconfig/network-scripts/ifcfg-e[Tab]
将ONBOOT=no改为ONBOOT=yes
systemctl stop firewalld.service #停止firewall firewall-cmd --state #查看默认防火墙状态(关闭后显示not running,开启后显示running) systemctl disable firewalld.service #禁止firewall开机启动

yum -y install net-tools
安装完后可以用ifconfig查看桥接网卡的ip地址,选一个自己喜欢的ssh客户端软件(如putty)连接到虚拟机。
nginx 手机端访问跳转到m站点
location / {
if ($http_user_agent ~* (mobile|nokia|iphone|ipad|android|samsung|htc|blackberry)) {
rewrite ^/(.*)$ http://m.1weidu.com/$1 permanent; #进行正常访问的时候判断user_agent为手机,则重写至此页面
}
try_files $uri /index.php?$args;
}
server {
listen 80;
server_name ~^(?<subdomain>.+)\.dev.domain.com;
root /data/dev/$subdomain/project;
index index.php;
charset utf-8;
access_log /var/log/nginx/domain.com-access.log;
error_log /var/log/nginx/domain.com-error.log;
location ~ .*\.(ico|gif|jpg|jpeg|png|bmp|swf)$ {
expires 30d;
}
location ~ .*\.(js|css)$ {
expires 10d;
}
location / {
try_files $uri /index.php?$args;
}
location ~ \.php$ {
fastcgi_index index.php;
fastcgi_pass 127.0.0.1:9000;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
}
这样在/data/dev/下新建开发者的目录,可以以开发者名字的全拼或简写命名,如:abc,然后在这个目录acb下开发对应的项目project,项目的访问地址为:abc.dev.domain.com。可以做域名解析或绑定host访问。
#!/bin/bash
#
# Startup script for Nginx - this script starts and stops the nginx daemon
#
# chkconfig: - 85 15
# description: Nginx is an HTTP(S) server, HTTP(S) reverse proxy and IMAP/POP3 proxy server
# processname: nginx
# config: /usr/local/nginx/conf/nginx.conf
# pidfile: /usr/local/nginx/logs/nginx.pid
# Source function library.
. /etc/rc.d/init.d/functions
# Source networking configuration.
. /etc/sysconfig/network
# Check that networking is up.
[ "$NETWORKING" = "no" ] && exit 0
nginx="/usr/local/nginx/sbin/nginx"
prog=$(basename $nginx)
NGINX_CONF_FILE="/usr/local/nginx/conf/nginx.conf"
[ -f /etc/sysconfig/nginx ] && . /etc/sysconfig/nginx
lockfile=/var/lock/subsys/nginx
start() {
[ -x $nginx ] || exit 5
[ -f $NGINX_CONF_FILE ] || exit 6
echo -n $"Starting $prog: "
daemon $nginx -c $NGINX_CONF_FILE
retval=$?
echo
[ $retval -eq 0 ] && touch $lockfile
return $retval
}
stop() {
echo -n $"Stopping $prog: "
killproc $prog -QUIT
retval=$?
echo
[ $retval -eq 0 ] && rm -f $lockfile
return $retval
}
restart() {
configtest || return $?
stop
sleep 1
start
}
reload() {
configtest || return $?
echo -n $"Reloading $prog: "
killproc $nginx -HUP
RETVAL=$?
echo
}
force_reload() {
restart
}
configtest() {
$nginx -t -c $NGINX_CONF_FILE
}
rh_status() {
status $prog
}
rh_status_q() {
rh_status >/dev/null 2>&1
}
case "$1" in
start)
rh_status_q && exit 0
$1
;;
stop)
rh_status_q || exit 0
$1
;;
restart|configtest)
$1
;;
reload)
rh_status_q || exit 7
$1
;;
force-reload)
force_reload
;;
status)
rh_status
;;
condrestart|try-restart)
rh_status_q || exit 0
;;
*)
echo $"Usage: $0 {start|stop|status|restart|condrestart|try-restart|reload|force-reload|configtest}"
exit 2
esac
widonws上用xshell生成用户秘钥免密码登录linux服务器,具体方法如下图:




注:这里给私钥起个名字,为了方便记忆可以以服务器的IP地址做文件名,点击Next。

注:把公钥也就是红色框内的全部内容添加到服务器的/home/username/.ssh/authorized_keys文件中。

这里显示了用户的所有私钥,当用public key方法登录时,需要选择对应的私钥

注:非root用户需要修改一下权限
chmod 700 /home/zhangsan/.ssh chmod 600 /home/zhangsan/.ssh/authorized_keys
只允许root用户之外的用户以公钥的形式登录。
vi /etc/ssh/sshd_config PasswordAuthentication no #禁止使用基于口令认证的方式登陆 PubkeyAuthentication yes #允许使用基于密钥认证的方式登陆 service sshd restart