转自:linux nginx配置新项目加域名

找到nginx的配置文件 nginx/nginx.conf

第一种方,法直接在nginx.com里面配置

  1. user www www;
  2.  
  3. worker_processes auto;
  4.  
  5. error_log /home/wwwlogs/nginx_error.log crit;
  6.  
  7. pid /usr/local/nginx/logs/nginx.pid;
  8.  
  9. #Specifies the value for maximum file descriptors that can be opened by this process.
  10. worker_rlimit_nofile 51200;
  11.  
  12. events
  13. {
  14. use epoll;
  15. worker_connections 51200;
  16. multi_accept on;
  17. }
  18.  
  19. http
  20. {
  21. include mime.types;
  22. default_type application/octet-stream;
  23.  
  24. server_names_hash_bucket_size 128;
  25. client_header_buffer_size 32k;
  26. large_client_header_buffers 4 32k;
  27. client_max_body_size 50m;
  28.  
  29. sendfile on;
  30. tcp_nopush on;
  31.  
  32. keepalive_timeout 60;
  33.  
  34. tcp_nodelay on;
  35.  
  36. fastcgi_connect_timeout 300;
  37. fastcgi_send_timeout 300;
  38. fastcgi_read_timeout 300;
  39. fastcgi_buffer_size 64k;
  40. fastcgi_buffers 4 64k;
  41. fastcgi_busy_buffers_size 128k;
  42. fastcgi_temp_file_write_size 256k;
  43.  
  44. gzip on;
  45. gzip_min_length 1k;
  46. gzip_buffers 4 16k;
  47. gzip_http_version 1.1;
  48. gzip_comp_level 2;
  49. gzip_types text/plain application/javascript application/x-javascript text/javascript text/css application/xml application/xml+rss;
  50. gzip_vary on;
  51. gzip_proxied expired no-cache no-store private auth;
  52. gzip_disable "MSIE [1-6]\.";
  53.  
  54. #limit_conn_zone $binary_remote_addr zone=perip:10m;
  55. ##If enable limit_conn_zone,add "limit_conn perip 10;" to server section.
  56.  
  57. server_tokens off;
  58. #log format
  59. log_format access '$remote_addr - $remote_user [$time_local] "$request" '
  60. '$status $body_bytes_sent "$http_referer" '
  61. '"$http_user_agent" $http_x_forwarded_for';
  62. access_log off;
  63.  
  64. server
  65. {
  66. listen 80;
  67. #listen [::]:80 default_server ipv6only=on;
  68. server_name www.beibeigou8.com beibeigou8.com; /**需要设置的域名**/
  69. index index.html index.htm index.php;
  70. root /home/wwwroot/weilang; /**项目地址**/
  71.  
  72. #error_page 404 /404.html;
  73. include enable-php.conf;
  74.  
  75. location /nginx_status
  76. {
  77. stub_status on;
  78. access_log off;
  79. }
  80.  
  81. location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)$
  82. {
  83. expires 30d;
  84. }
  85.  
  86. location ~ .*\.(js|css)?$
  87. {
  88. expires 12h;
  89. }
  90.  
  91. location ~ /\.
  92. {
  93. deny all;
  94. }
  95.  
  96. access_log /home/wwwlogs/access.log access;
  97.  
  98. }
  99. include vhost/*.conf;
  100. }

要配置新项目的话,需要重新复制service所有内容,如

  1. server
  2. {
  3. listen 80;
  4. #listen [::]:80 default_server ipv6only=on;
  5. server_name www.beibeigou8.com beibeigou8.com;
  6. index index.html index.htm index.php;
  7. root /home/wwwroot/weilang;
  8.  
  9. #error_page 404 /404.html;
  10. include enable-php.conf;
  11.  
  12. location /nginx_status
  13. {
  14. stub_status on;
  15. access_log off;
  16. }
  17.  
  18. location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)$
  19. {
  20. expires 30d;
  21. }
  22.  
  23. location ~ .*\.(js|css)?$
  24. {
  25. expires 12h;
  26. }
  27.  
  28. location ~ /\.
  29. {
  30. deny all;
  31. }
  32.  
  33. access_log /home/wwwlogs/access.log access;
  34.  
  35. }
  36. server
  37. {
  38. listen 80;
  39. #listen [::]:80 default_server ipv6only=on;
  40. server_name www.2345.2345.com;
  41. index index.html index.htm index.php;
  42. root /home/wwwroot/2345;
  43.  
  44. #error_page 404 /404.html;
  45. include enable-php.conf;
  46.  
  47. location /nginx_status
  48. {
  49. stub_status on;
  50. access_log off;
  51. }
  52.  
  53. location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)$
  54. {
  55. expires 30d;
  56. }
  57.  
  58. location ~ .*\.(js|css)?$
  59. {
  60. expires 12h;
  61. }
  62.  
  63. location ~ /\.
  64. {
  65. deny all;
  66. }
  67.  
  68. access_log /home/wwwlogs/access.log access;
  69. }

第二种方法,用includ导入(方便各种域名管理)

  1. user www www;
  2.  
  3. worker_processes auto;
  4.  
  5. error_log /home/wwwlogs/nginx_error.log crit;
  6.  
  7. pid /usr/local/nginx/logs/nginx.pid;
  8.  
  9. #Specifies the value for maximum file descriptors that can be opened by this process.
  10. worker_rlimit_nofile 51200;
  11.  
  12. events
  13. {
  14. use epoll;
  15. worker_connections 51200;
  16. multi_accept on;
  17. }
  18.  
  19. http
  20. {
  21.  
  22. server
  23. {
  24.  
  25. }
  26. include vhost/*.conf;
  27. }

nginx/vhost目录下文件

文件名:www.beibeigou8.com.conf  (直接域名配置)

内容:

  1. server{
  2. listen 80;
  3. server_name www.beibeigou8.com;
  4. index index.html index.htm index.php;
  5. root /home/wwwroot/weilang;
  6. #if (!-e $request_filename) {
  7. # rewrite ^/(.*)$ /index.php/$1 last;
  8. # break;
  9. #}
  10. #error_page 404 /404.html;
  11. #include enable-php.conf;
  12.  
  13. location /nginx_status
  14. {
  15. stub_status on;
  16. access_log off;
  17. }
  18.  
  19. location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)$
  20. {
  21. expires 30d;
  22. }
  23.  
  24. location ~ .*\.(js|css)?$
  25. {
  26. expires 12h;
  27. }
  28.  
  29. location ~ /\.
  30. {
  31. deny all;
  32. }
  33.  
  34. location ^~ /phpmyadmin/
  35. {
  36. deny all;
  37. }
  38.  
  39. location ^~ /data/
  40. {
  41. deny all;
  42. }
  43.  
  44. #location ~ ^(.+\.php)(.*)$ {
  45. location ~ .php {
  46. root /home/wwwroot/weilang;
  47. fastcgi_pass 127.0.0.1:9000;
  48. fastcgi_index index.php;
  49. include fastcgi.conf;
  50. #fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
  51. #include fastcgi_params;
  52. #set $path_info "";
  53. #set $real_script_name $fastcgi_script_name;
  54. #if ($fastcgi_script_name ~ "^(.+?\.php)(/.+)$") {
  55. # set $real_script_name $1;
  56. # set $path_info $2;
  57. #}
  58. #fastcgi_param SCRIPT_FILENAME $document_root$real_script_name;
  59. #fastcgi_param SCRIPT_NAME $real_script_name;
  60. #fastcgi_param PATH_INFO $path_info;
  61. }
  62. access_log /home/wwwlogs/access.log access;
  63. }

文件名:beibeigou8.com.conf (中间有静态跳转)

内容:

  1. server{
  2. listen 80;
  3. server_name beibeigou8.com;
  4. index index.html index.htm index.php;
  5. #root /home/wwwroot/weilang;
  6. #if (!-e $request_filename) {
  7. # rewrite ^/(.*)$ /index.php/$1 last;
  8. # break;
  9. #}
  10. #error_page 404 /404.html;
  11. #include enable-php.conf;
  12.  
  13. rewrite ^/$ http://www.beibeigou8.com/ permanent;
  14.  
  15. location /nginx_status
  16. {
  17. stub_status on;
  18. access_log off;
  19. }
  20.  
  21. location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)$
  22. {
  23. expires 30d;
  24. }
  25.  
  26. location ~ .*\.(js|css)?$
  27. {
  28. expires 12h;
  29. }
  30.  
  31. location ~ /\.
  32. {
  33. deny all;
  34. }
  35. #location ~ ^(.+\.php)(.*)$ {
  36. location ~ .php {
  37. root /home/wwwroot/weilang;
  38. fastcgi_pass 127.0.0.1:9000;
  39. fastcgi_index index.php;
  40. fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
  41. include fastcgi_params;
  42. set $path_info "";
  43. set $real_script_name $fastcgi_script_name;
  44. if ($fastcgi_script_name ~ "^(.+?\.php)(/.+)$") {
  45. set $real_script_name $1;
  46. set $path_info $2;
  47. }
  48. fastcgi_param SCRIPT_FILENAME $document_root$real_script_name;
  49. fastcgi_param SCRIPT_NAME $real_script_name;
  50. fastcgi_param PATH_INFO $path_info;
  51. }
  52. access_log /home/wwwlogs/access.log access;
  53. }

linux nginx配置新项目加域名(设置绑定域名)的更多相关文章

  1. linux nginx配置新项目加域名

    找到nginx的配置文件 nginx/nginx.conf 第一种方,法直接在nginx.com里面配置 user www www; worker_processes auto; error_log ...

  2. 在Linux上配置xampp后远程访问域名报错

    在Linux上配置xampp后远程访问域名报错: New XAMPP security concept: Access to the requested object is only availabl ...

  3. linux nginx 配置php

    linux nginx 配置php   下载php源码 解压 configure ./configure --prefix=/usr/local/php --enable-fpm --with-mcr ...

  4. 记一次mac下使用mamp集成环境配置lumen项目自定义域名遇到的花样问题

    1.安装好mamp集成环境,自行百度. 2.从公司项目版本库里将项目克隆到本地. 好了,开始配置自定义域名来访问项目,以下是遇到的问题集锦... 1.web服务器使用的nginx,配置完域名访问报40 ...

  5. Nginx配置多个基于域名的虚拟主机+实验环境搭建+测试

    标签:Linux 域名 Nginx 原创作品,允许转载,转载时请务必以超链接形式标明文章 原始出处 .作者信息和本声明.否则将追究法律责任.http://xpleaf.blog.51cto.com/9 ...

  6. Nginx配置Web项目(多页面应用,单页面应用)

    目前前端项目 可分两种: 多页面应用,单页面应用. 单页面应用 入口是一个html文件,页面路由由js控制,动态往html页面插入DOM. 多页面应用 是由多个html文件组成,浏览器访问的是对应服务 ...

  7. nginx配置一、二级域名、多域名对应(api接口、前端网站、后台管理网站)

    前提:安装好nginx,如果已经启动nginx,先停止,命令: ./usr/local/nginx/sbin/nginx -s stop 修改nginx配置 vi /usr/local/nginx/c ...

  8. 在linux上配置Django项目

    依赖包 [root@web01 ~]# yum install openssl-devel bzip2-devel expat-devel gdbm-devel readline-devel sqli ...

  9. nginx 配置Tp5项目时出现 404 Not Found nginx

    1.首先看了nginx报错日志 报 signal process started signal process started表示还有 产生原因 1.可能你的nginx.conf 内容配置的有问题. ...

随机推荐

  1. Linux上安装Hadoop集群(CentOS7+hadoop-2.8.0)

    1下载hadoop 2安装3个虚拟机并实现ssh免密码登录 2.1安装3个机器 2.2检查机器名称 2.3修改/etc/hosts文件 2.4 给3个机器生成秘钥文件 2.5 在hserver1上创建 ...

  2. 深入浅出Nodejs读书笔记

    深入浅出Nodejs读书笔记 转:http://tw93.github.io/2015-03-01/shen-ru-qian-chu-nodejs-reading-mind-map.html cate ...

  3. linux下判断文件和目录是否存在[总结]

    1.前言 工作中涉及到文件系统,有时候需要判断文件和目录是否存在.我结合APUE第四章文件和目录,总结一下如何正确判断文件和目录是否存在,方便以后查询. 2.stat系列函数 stat函数用来返回与文 ...

  4. 前端框架 Vue 初探

    一.前言 前几日使用微信网页版时,好奇这个网页用了什么前端框架.用Chrome的开发人员模式一探到底,发现原来用了一个名叫 Angular 的框架.好吧,既然微信用了.那我也最好还是看看.等等,你这篇 ...

  5. 基于spring与mockito单元测试Mock对象注入

    转载:http://www.blogjava.net/qileilove/archive/2014/03/07/410713.html 1.关键词 单元测试.spring.mockito 2.概述 单 ...

  6. [Canvas]游戏增加怪物爆炸效果,改善箭头形状

    请点此下载代码并用浏览器打开试玩. 图例: 代码: <!DOCTYPE html> <html lang="utf-8"> <meta http-eq ...

  7. centos6默认python2.6升级2.7 卸载python2.6升级2.7

    转自:http://blog.csdn.net/u010098331/article/details/52190354 本文介绍CentOS 6.3从自带的Pyhon版本是2.6升级到2.7.6的方法 ...

  8. C语言处理文件

    C写入数据到文件 #include <stdio.h> #include <string.h> int main( ) { FILE* fd = fopen("txt ...

  9. jQuery开发技巧

    jQuery 事件 - submit() 方法 $("form").submit(function(e){}); 当提交表单时,会发生 submit 事件. 该事件只适用于表单元素 ...

  10. python 爬虫 爬取序列博客文章列表

    python中写个爬虫真是太简单了 import urllib.request from pyquery import PyQuery as PQ # 根据URL获取内容并解码为UTF-8 def g ...