Vagrant中Nginx配置
来源:互联网 发布:2017网络流行语汇总 编辑:程序博客网 时间:2024/05/27 06:51
在系列文章1和系列文章2文章中,介绍了Vagrant的安装和开发环境软件的自动安装。
这篇文章将写点关于虚拟机中Nginx的配置,以及在真实机中访问Nginx的方法。
打开Vagrantfile文件中,找到如下配置:
config.vm.network "forwarded_port", guest: 80, host: 8080
该配置的意思就是将虚拟机的80端口映射到真实机的8080端口。
使用vagrant ssh
命令进入虚拟机
备份默认nginx配置文件
sudo cp /etc/nginx/nginx.conf /etc/nginx/nginx.conf.back
修改配置
打开/etc/nginx/nginx.conf
,将里面的内容更改如下:
user www-data;worker_processes 4;pid /var/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; ## # 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 6; gzip_buffers 16 8k; gzip_http_version 1.1; gzip_types text/plain text/css application/json application/x-javascript text/xml application/xml application/xml+rss text/javascript; ## # nginx-naxsi config ## # Uncomment it if you installed nginx-naxsi ## #include /etc/nginx/naxsi_core.rules; ## # nginx-passenger config ## # Uncomment it if you installed nginx-passenger ## #passenger_root /usr; #passenger_ruby /usr/bin/ruby; ## # Virtual Host Configs ## include /etc/nginx/conf.d/*.conf; include /etc/nginx/sites-enabled/*; include /vagrant/files/nginx/conf.d/*.conf; server { listen 80; server_name lanffy.com www.lanffy.com; charset utf-8; index index.html index.htm; root /projects/; }}
添加HTML页面
在虚拟机中:cd /projects
在该目录下新建index.html或者index.htm文件,内容如下:
<html> <head> <title>R_Lanffy</title> </head> <body> Hello World </body></html>
重启Vagrant
vagrant reload
修改hosts
sudo vim /etc/hosts
添加:127.0.0.1 www.lanffy.com
访问测试
在真实机浏览器中输入地址:lanffy.com:8080
或者www.lanffy.com:8080
即可访问到虚拟机中的nginx相关配置。
如果想达到输入test.com就能访问的目的,是需要将Vagrantfile文件中的8080修改为80
注:如果出现不能访问的情况,很有可能是在启动虚拟机之前,8080端口被占用了。解决办法就是将端口修改为没有被占用的端口。
查看端口是否被监听:netstat -an | grep 8080
0 0
- Vagrant中Nginx配置
- vagrant中Vagrantfile配置
- vagrant配置linux以及nginx开发环境
- vagrant 的下 nginx
- vagrant nginx 操作
- 配置salt+vagrant
- 安装配置Vagrant
- vagrant基本配置使用
- vagrant环境配置
- Vagrant安装配置
- vagrant配置多机多节点
- vagrant+vitrulbox配置问题
- vagrant 配置多目录
- vagrant 安装与配置
- 安装Vagrant中
- nginx中配置SSL
- nginx中conf配置
- Nginx中gzip配置
- android仿照IOS AppStore下载进度条
- SCN 使用详细介绍
- VisualSvn Server的安装与使用
- spring mvc拦截器和<mvc:annotation-driven />的详解
- iOS Good Practices
- Vagrant中Nginx配置
- linux命令---scp命令
- LeetCode 35: Search Insert Position
- 一看就会Android之按钮Button和图片按钮ImageButton的用法
- register_chrdev_region()、alloc_chrdev_region() 和 register_chrdev()
- iOS多线程2 Opertaion补充
- solr教程,值得刚接触搜索开发人员一看
- POJ 2004 Hire and Fire(树+好题)
- 由linux0.11进程调度小窥内存分段机制(转)