论坛风格切换
  • 6484阅读
  • 6回复

[linux服务器]nginx域名绑定,启动,伪静态,一帖通 [复制链接]

上一主题 下一主题
离线太史慈
 

发帖
766
金币
626
威望
556
只看楼主 倒序阅读 使用道具 楼主  发表于: 2011-07-19
— 本帖被 云天河 执行加亮操作(2011-07-20) —
nginx域名绑定,启动,伪静态,一帖通http://phpwind.me/290.html
apache域名绑定,启动,伪静态,一帖通http://phpwind.me/291.html
iis域名绑定,启动,伪静态,一帖通http://phpwind.me/292.html


首先,先判断服务器上有没使用nginx,可以使用命令
  1. ps -aux|grep nginx

如果nginx启动正常的话,会显示

我们看到
nginx: master process /alidata/server/nginx/sbin/nginx

说明nginx主进程启动正常,且目录是/alidata/server/nginx/

我们找到nginx的配置文件/alidata/server/nginx/conf/nginx.conf,打开后

[url=http://www.phpwind.com]phpwind[/url]
离线太史慈

发帖
766
金币
626
威望
556
只看该作者 沙发  发表于: 2011-07-19
一个比较纯净的nginx配置文件
  1. user  www www;
  2. worker_processes  2;
  3. error_log  /alidata/server/nginx/logs/error.log  crit;
  4. pid        /alidata/server/nginx/logs/nginx.pid;
  5. #Specifies the value for maximum file descriptors that can be opened by this process.
  6. worker_rlimit_nofile 65535;
  7. events
  8. {
  9.   use epoll;
  10.   worker_connections 65535;
  11. }
  12. http {
  13.     include       mime.types;
  14.     default_type  application/octet-stream;
  15.     #charset  gb2312;
  16.     server_names_hash_bucket_size 128;
  17.     client_header_buffer_size 32k;
  18.     large_client_header_buffers 4 32k;
  19.     client_max_body_size 8m;
  20.     sendfile on;
  21.     tcp_nopush     on;
  22.     keepalive_timeout 60;
  23.     tcp_nodelay on;
  24.     fastcgi_connect_timeout 300;
  25.     fastcgi_send_timeout 300;
  26.     fastcgi_read_timeout 300;
  27.     fastcgi_buffer_size 64k;
  28.     fastcgi_buffers 4 64k;
  29.     fastcgi_busy_buffers_size 128k;
  30.     fastcgi_temp_file_write_size 128k;
  31.     gzip on;
  32.     gzip_min_length  1k;
  33.     gzip_buffers     4 16k;
  34.     gzip_http_version 1.0;
  35.     gzip_comp_level 2;
  36.     gzip_types       text/plain application/x-javascript text/css application/xml;
  37.     gzip_vary on;
  38.     #limit_zone  crawler  $binary_remote_addr  10m;
  39. server {
  40.         listen       80;
  41.         server_name  localhost;
  42.     index index.html index.htm index.php;
  43.     root /alidata/www/;
  44.     location ~ .*\.(php|php5)?$
  45.     {      
  46.         #fastcgi_pass  unix:/tmp/php-cgi.sock;
  47.         fastcgi_pass  127.0.0.1:9000;
  48.         fastcgi_index index.php;
  49.         include fastcgi.conf;
  50.     }
  51.     location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)$
  52.     {
  53.         expires 30d;
  54.     }
  55.     location ~ .*\.(js|css)?$
  56.     {
  57.         expires 1h;
  58.     }
  59.     log_format  main  '$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  /alidata/server/nginx/logs/access.log  main;
  63.     }
  64.     # another virtual host using mix of IP-, name-, and port-based configuration
  65.     #
  66.     #server {
  67.     #    listen       8000;
  68.     #    listen       somename:8080;
  69.     #    server_name  somename  alias  another.alias;
  70.     #    location / {
  71.     #        root   html;
  72.     #        index  index.html index.htm;
  73.     #    }
  74.     #}
  75.     # HTTPS server
  76.     #
  77.     #server {
  78.     #    listen       443;
  79.     #    server_name  localhost;
  80.     #    ssl                  on;
  81.     #    ssl_certificate      cert.pem;
  82.     #    ssl_certificate_key  cert.key;
  83.     #    ssl_session_timeout  5m;
  84.     #    ssl_protocols  SSLv2 SSLv3 TLSv1;
  85.     #    ssl_ciphers  ALL:!ADH:!EXPORT56:RC4+RSA:+HIGH:+MEDIUM:+LOW:+SSLv2:+EXP;
  86.     #    ssl_prefer_server_ciphers   on;
  87.     #    location / {
  88.     #        root   html;
  89.     #        index  index.html index.htm;
  90.     #    }
  91.     #}
  92. }


[url=http://www.phpwind.com]phpwind[/url]
离线太史慈

发帖
766
金币
626
威望
556
只看该作者 板凳  发表于: 2011-07-19
如何绑新的域名
我们分析下它的结构
  1. http {
  2.   server {
  3.     web站点1
  4.   }
  5.   server {
  6.     web站点2
  7.   }
  8.   server {
  9.     web站点3
  10.   }
  11. }


我们看上面那个纯净的配置文件,里面只有一个server,说明只有一个web站点,所以我们需要做的是把server这一大段复制一份出来。
当然我们还需要改几个东西,看几个重要参数:

1。
  1. server_name  localhost;

这里可以改成您的域名,比如
  1. server_name www.phpwind.me phpwind.me;

注意点,加多个域名的话,用空格隔开。

2。
  1. index index.html index.htm index.php;

站点默认打开的文件

3。
  1. root /alidata/www/;

web路径

4。
  1. access_log  /alidata/server/nginx/logs/access.log  main;

站点日志文件,不改掉会出错的

[url=http://www.phpwind.com]phpwind[/url]
离线太史慈

发帖
766
金币
626
威望
556
只看该作者 地板  发表于: 2011-07-19
重新启动nginx
继1楼后,我们看到nginx的主进程是869
我们执行
  1. kill -HUP 869

即可,当然也可以
  1. kill -HUP /alidata/server/nginx/logs/nginx.pid

其中nginx.pid存储的是nginx的主进程号
以上是平滑修改nginx配置的方法

nginx重启方法
  1. /usr/local/nginx/sbin/nginx -s reload

检测nginx配置文件有无故障
  1. /usr/local/nginx/sbin/nginx -t


第一句检查配置文件是否正确,正确信息:
the configuration file /usr/local/nginx/conf/nginx.conf syntax is ok
the configuration file /usr/local/nginx/conf/nginx.conf was tested successfully
[url=http://www.phpwind.com]phpwind[/url]
离线太史慈

发帖
766
金币
626
威望
556
只看该作者 4楼 发表于: 2011-07-19
启动nginx时几种常见错误
[url=http://www.phpwind.com]phpwind[/url]
离线太史慈

发帖
766
金币
626
威望
556
只看该作者 5楼 发表于: 2011-07-19
nginx伪静态
[url=http://www.phpwind.com]phpwind[/url]
离线太史慈

发帖
766
金币
626
威望
556
只看该作者 6楼 发表于: 2011-07-20
nginx 重定向301和错误页面404和502等
[url=http://www.phpwind.com]phpwind[/url]
快速回复
限100 字节
如果您提交过一次失败了,可以用”恢复数据”来恢复帖子内容
 
提到某人:
选择好友
上一个 下一个