ubuntu服务器nginx搭建网站,ubuntu 16.04配置nginx服务器实现一个IP一个端口多个站点...

3da863cc448ee0c27f91143a84fd8f2e.jpg

特点:

Nginx 可以部署在网络上使用 FastCGI,脚本,SCGI 处理程序,WSGI 应用服务器或 Phusion 乘客模块的动态 HTTP 内容,并可作为软件负载均衡器。

Nginx 使用异步事件驱动的方法来处理请求。 Nginx的模块化事件驱动架构可以在高负载下提供更可预测的性能。

Nginx是一款面向性能设计的HTTP服务器,相较于Apache、lighttpd具有占有内存少,稳定性高等优势。与旧版本(<=2.2)的Apache不同,nginx不采用每客户机一线程的设计模型,而是充分使用异步逻辑,削减了上下文调度开销,所以并发服务能力更强。整体采用模块化设计,有丰富的模块库和第三方模块库,配置灵活。 在Linux作业系统下,nginx使用epoll事件模型,得益于此,nginx在Linux作业系统下效率相当高。同时Nginx在OpenBSD或FreeBSD作业系统上采用类似于epoll的高效事件模型kqueue。

实现两个域名,打开两个不同的站点

把0522.com和0o0.live解析到同一个IP

检查nginx配置文件

vim /etc/nginx/nginx.conf

确保,配置文件的http{}大括号里有:

include /etc/nginx/conf.d/*.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 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; ## # Virtual Host Configs ## include /etc/nginx/conf.d/*.conf; #就是这里,如果前面有#号,请把#号去掉 include /etc/nginx/sites-enabled/*; }

在目录/etc/nginx/conf.d/下面新建两个文件:

0522.conf 0o0.conf #.conf前的名字随你

写入以下内容:

server { listen 80; server_name 0522.us www.0522.us; #这里填写你的域名,包括无www301转向有www index index.html index.htm index.php default.html default.htm default.php; root /var/www/0522.us; #这里填写域名对应的站点根目录 location / { try_files $uri $uri/ /index.php; } location ~ .php$ { try_files $uri =404; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; include fastcgi_params; fastcgi_pass unix:/var/run/php/php7.0-fpm.sock; } location ~ .*.(gif|jpg|jpeg|png|bmp|swf|ico)$ { expires 30d; } location ~ .*.(js|css)?$ { expires 30d; } }

以上是0522.conf的内容

server { listen 80; server_name 0o0.live www.0o0.live; index index.html index.htm index.php default.html default.htm default.php; root /var/www/0o0.live; location / { try_files $uri $uri/ /index.php; } location ~ .php$ { try_files $uri =404; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; include fastcgi_params; fastcgi_pass unix:/var/run/php/php7.0-fpm.sock; } location ~ .*.(gif|jpg|jpeg|png|bmp|swf|ico)$ { expires 30d; } location ~ .*.(js|css)?$ { expires 30d; } }

以上是0o0.conf的内容

重启nginx

sudo service nginx restart #所有nginx的设置要重启后才先效

分别上传两个域名的不同网站文件到相应的网站根目录

例如:

0522.us域名上传网站文件到/var/www/0522.us目录下 0o0.live域名上传网站文件到/var/www/0o0.live目录下 #你的域名上传到你自己设置的根目录

完美

原文出处:0lddriver -> http://www.0lddriver.com/ubuntu-16-04%E9%85%8D%E7%BD%AEnginx%E6%9C%8D%E5%8A%A1%E5%99%A8%E5%AE%9E%E7%8E%B0%E4%B8%80%E4%B8%AAip%E4%B8%80%E4%B8%AA%E7%AB%AF%E5%8F%A3%E5%A4%9A%E4%B8%AA%E7%AB%99%E7%82%B9/

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值