在Ubuntu上安装Nginx简单方法

在Ubuntu上安装Nginx简单方法

1、安装Nginx

apt-get install nginx

(要最新版本下载下来编译吧) 装完应该能正常运行了。如果之前有装APACHE要改下端口。。。或者直接

apt-get	remove	apache2		
/etc/init.d/nginx stop		
/etc/init.d/nginx start

2、安装php-cgi

apt-get install php-cgi

(要自定义安装的编译吧)
3、改php-cgi的配置 Ubuntu下是/etc/php5/cgi/php.ini 之前有安装过php的话会复制apache的配置文件 打开cgi.fix_pathinfo选项:

cgi.fix_pathinfo=1;

4、改Nginx的fastcgi传递参数 Ubuntu下是/etc/nginx/fastcgi_params 默认应该已经设置好了,内容差不多就下面那样: 代码:

fastcgi_ param QUERY_ STRING $query_ string;
fastcgi_ param REQUEST METHOD $request_ method;
fastcgi_ param CONTENT TYPE $content_ type;
fastcgi_ param CONTENT LENGTH $content length; fastcgi_ param SCRIPT_ NAME $fastcgi_ script_ na
fastcg1_ param REQUEST_ _URI Srequest_ uri;
fastcg1_ param DOCUMENT_ URI $document_ _uri;
fastcg1_ param DOCUMENT_ _ROOT $document_ root;
fastcg1_ param SERVER_ PROTOCOL $server_ protocol;
fastcgi_ param GATEWAY_ INTERFACE CGI/1.1;
fastcg1_ param SERVER_ SOFTWARE nginx/snginx_ version; 
fastcg1_ param REMOTE_ ADDR Sremote_ addr;
fastcgi_ param REMOTE_ PORT $remote_ port; 
fastcg1_ param SERVER_ ADDR sserver_ addr ;
fastcg1_ param SERVER_ PORT sserver_ port;
fastcg1_ param SERVER_ NAME sserver_ name;
# PHP only, required if PHP was built with -enable-force-cgi-redirect
fastcg1_ param REDIRECT _STATUS 200;

5、创建VHost配置(这里只说Ubuntu下的,也就路径和包含文件目录的区别了)
在/etc/nginx/sites-available/下创建服务器配置文件比如myserver

1n -n /etc/nginx/sites- available/myserver /etc/nginx/sites-enabled/myserver

其实懒的话直接创建在enabled里也没问题-。- 内容填: 代码:

server {
listen 80;
server_ name myserver 。com;
access_ 10g /var /10g/nginx/myserver . access. log;location / {
root /wwwroot/myserver ;
index index . php;
autoindex off ; 
location ~ \.php$ {
include /etc/nginx/fastcg1_ params;
fastcgi_ param SCRIPT_ FILENAME /wwwroot/myserver /$fastcgi_ script_ name;
fastcg1_ pass 127 .0.0.1: 9000;
fastcg1_ index index . php ;
# redirect server error pages to the static page /50X。html
error_ _page 500 502 503 504 /50x. html;
location = /50x.html {
root /var /www/nginx-defau1t;
# deny access to .htaccess files, if Apache's document root
1ocation一八.ht {
deny al1;

在Ubuntu上安装Nginx简单方法
6、安装spawn-fcgi
下载可到这里,这东西已经独立出来了
https://redmine.lighttpd.net/projects/spawn-fcgi/wiki
下完后解压编译

sudo ./configure -prefix=/usr/local
sudo make
sudo make
install

7、启动spaw-fcgi

sudo spawn-fcgi -a 127.0.0.1 -p 9000 -u www-data -g www-data -f /usr/bin/php5-cgi -F 10

哦,对后面10进程不爽的人可以取消或是加到100
8、重启Nginx

/etc/init.d/nginx restart

9、定义下hosts就可以看结果啦
编辑/etc/hosts加入

127.0.0.1 myserver.com

然后打开浏览器就可以看结果啦〜 有问题欢迎指出〜〜

原创文章,作者:小 编,如若转载,请注明出处:https://www.mzbky.com/716.html

发表评论

登录后才能评论