CentOS上搭建Nginx + Mono 运行 asp.net

安装步骤:

一、获取开源相关程序:

1、利用CentOS Linux系统自带的yum命令安装、升级所需的程序库:

sudo -s
LANG=C
yum -y install gcc gcc-c++ autoconf libjpeg libjpeg-devel libpng libpng-devel freetype freetype-devel libxml2 libxml2-devel zlib zlib-devel glibc glibc-devel glib2 glib2-devel bzip2 bzip2-devel bison pkgconfig glib2-devel gettext make

2、下载程序源码包:

Nginx安装包:下载地址:http://nginx.org/en/download.html

mkdir -p /down
cd /down
wget http://nginx.org/download/nginx-1.1.11.tar.gz


Mono下载:官网:http://download.mono-project.com/sources/mono/(请下载最新版)

wget http://download.mono-project.com/sources/mono/mono-2.10.7.tar.bz2

libgdiplus下载:http://download.mono-project.com/sources/libgdiplus/(请下载最新版)

wget http://download.mono-project.com/sources/libgdiplus/libgdiplus-2.10.tar.bz2

 xsp下载:http://download.mono-project.com/sources/xsp/(请下载最新版)

wget http://download.mono-project.com/sources/xsp/xsp-2.10.2.tar.bz2

pcre下载(Nginx所需的pcre库):ftp://ftp.csx.cam.ac.uk/pub/software/programming/pcre/(请下最新版)

wget ftp://ftp.csx.cam.ac.uk/pub/software/programming/pcre/pcre-8.21.tar.gz
二、安装编译Nginx:

1、安装安装Nginx所需的pcre库:

cd /down
tar zxvf pcre-8.21.tar.gz
cd pcre-8.21/
./configure
make && make install
cd ../

2、创建www用户和组

/usr/sbin/groupadd www
/usr/sbin/useradd -g www www
mkdir -p /data0/web
chmod +w /data0/web
chown -R www:www /data0/web

3、安装Nginx

tar zxvf nginx-1.1.11.tar.gz
cd nginx-1.1.11/
./configure --user=www --group=www --prefix=/opt/nginx --with-http_stub_status_module --with-http_ssl_module
make && make install
cd ../

 

4、开放80端口:

iptables -I INPUT -p tcp --dport 80 -j ACCEPT
启动nginx 
/opt/nginx/sbin/nginx

在浏览器上输入访问地址 http://192.168.1.1(根据个人本机地址页定),正常会看到默认nginx页面

 

三、安装编译Mono

1、安装libgdiplus:

复制代码
cd /down

tar -jxvf libgdiplus-2.10.tar.bz2
cd libgdiplus-2.10
./configure --prefix=/opt/mono 
make && make install
echo "/opt/mono/lib" > /etc/ld.so.conf.d/mono.conf
ldconfig 
复制代码

2、安装Mono:

复制代码
tar –jxvf mono-2.10.7.tar.bz2
cd mono-2.10.7
./configure --prefix=/opt/mono
make && make install //此处时间较长

echo export PKG_CONFIG_PATH=/opt/mono/lib/pkgconfig:$PKG_CONFIG_PATH>>~/.bash_profile
echo export LD_LIBRARY_PATH=/opt/mono/lib:$LD_LIBRARY_PATH>>~/.bash_profile
echo export PATH=/opt/mono/bin:$PATH>>~/.bash_profile
source ~/.bash_profile
复制代码

 输入 mono -V 如有mono版本信息,则安装成功. 

3、安装XSP:

cd /down
tar –jxvf xsp-2.10.2.tar.bz2
./configure --prefix=/opt/mono
make && make install

 

四、配置Nginx
vi /opt/nginx/conf/nginx.conf
复制代码
server {
         listen   80;
         server_name  localhost;
         location / {
                 root /data0/web;
                 index index.html index.htm;
                 fastcgi_index Default.aspx;
                 fastcgi_pass 127.0.0.1:9000;
                 include fastcgi_params;
         }
 }
复制代码

 

五、配置fastcgi_params增加下面两行:
vi /opt/nginx/conf/fastcgi_params
fastcgi_param  PATH_INFO          "";
fastcgi_param  SCRIPT_FILENAME    $document_root$fastcgi_script_name;

 

六、启动:

1、重启nginx:

/opt/nginx/sbin/nginx -s reload

2、启动 fastcgi_mono服务器

fastcgi-mono-server2 /applications=/:/data0/web /socket=tcp:127.0.0.1:9000 &

 

七、测试:

新建一个asp.net web项目上传至 /data0/web目录下,测试运行。

八. 指定配置文件

poechant@ubuntu:sudo ./sbin/nginx -c /usr/local/nginx/conf/nginx.conf

-c表示configuration,指定配置文件。

九.查看Nginx版本

有两种可以查看 Nginx 的版本信息的参数。第一种如下:

poechant@ubuntu:/usr/local/nginx$ ./sbin/nginx -v
nginx: nginx version: nginx/1.0.0

另一种显示的是详细的版本信息:

poechant@ubuntu:/usr/local/nginx$ ./sbin/nginx -V
nginx: nginx version: nginx/1.0.0
nginx: built by gcc 4.3.3 (Ubuntu 4.3.3-5ubuntu4) 
nginx: TLS SNI support enabled
nginx: configure arguments: --with-http_ssl_module --with-openssl=/home/luming/openssl-1.0.0d/

十. 检查配置文件是否正确

poechant@ubuntu:/usr/local/nginx$ ./sbin/nginx -t
nginx: [alert] could not open error log file: open() "/usr/local/nginx/logs/error.log" failed (13: Permission denied)
nginx: the configuration file /usr/local/nginx/conf/nginx.conf syntax is ok
2012/01/09 16:45:09 [emerg] 23898#0: open() "/usr/local/nginx/logs/nginx.pid" failed (13: Permission denied)
nginx: configuration file /usr/local/nginx/conf/nginx.conf test failed

如果出现如上的提示信息,表示没有访问错误日志文件和进程,可以sudosuper user do)一下:

poerchant@ubuntu:/usr/local/nginx$ sudo ./sbin/nginx -t
nginx: the configuration file /usr/local/nginx/conf/nginx.conf syntax is ok
nginx: configuration file /usr/local/nginx/conf/nginx.conf test is successful

如果显示如上,则表示配置文件正确。否则,会有相关提示。

十一. 显示帮助信息

poechant@ubuntu:/user/local/nginx$ ./sbin/nginx -h

或者:

poechant@ubuntu:/user/local/nginx$ ./sbin/nginx -?

以上这些涵盖了 Nginx 日常维护的所有基本操作,另外还有向 master 进程发送信号的相关命令,我们会在后续看到。



  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
好的,我知道你的问题了。针对你的问题,我可以给你一些简单的部署步骤: 1.安装nginx和PHP 在CentOS 6.8中安装nginx和PHP的方式如下: ``` sudo yum install nginx sudo yum install php-fpm ``` 2.配置nginx 在配置nginx之前,你需要备份一下默认的nginx配置文件。备份命令如下: ``` sudo cp /etc/nginx/nginx.conf /etc/nginx/nginx.conf.bak ``` 然后,你可以通过编辑/etc/nginx/nginx.conf文件来配置nginx。 下面是一个简单的nginx配置示例,可以将它添加到/etc/nginx/nginx.conf文件中: ``` user nginx; worker_processes auto; error_log /var/log/nginx/error.log; pid /run/nginx.pid; events { worker_connections 1024; } http { include /etc/nginx/mime.types; default_type application/octet-stream; log_format main '$remote_addr - $remote_user [$time_local] "$request" ' '$status $body_bytes_sent "$http_referer" ' '"$http_user_agent" "$http_x_forwarded_for"'; access_log /var/log/nginx/access.log main; sendfile on; keepalive_timeout 65; include /etc/nginx/conf.d/*.conf; server { listen 80; server_name localhost; root /usr/share/nginx/html; index index.php index.html index.htm; location / { try_files $uri $uri/ /index.php; } location ~ \.php$ { try_files $uri =404; fastcgi_pass unix:/var/run/php-fpm/php-fpm.sock; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; include fastcgi_params; } } } ``` 在这个示例配置中,我们将nginx的根目录设置为/usr/share/nginx/html,并且将index.php添加到默认文档列表中。同时,我们还配置了一个location块,用于处理PHP文件。 3.配置PHP 在配置PHP之前,你需要备份一下默认的php-fpm配置文件。备份命令如下: ``` sudo cp /etc/php-fpm.d/www.conf /etc/php-fpm.d/www.conf.bak ``` 然后,你可以通过编辑/etc/php-fpm.d/www.conf文件来配置PHP。 下面是一个简单的PHP配置示例,可以将它添加到/etc/php-fpm.d/www.conf文件中: ``` [www] user = nginx group = nginx listen = /var/run/php-fpm/php-fpm.sock listen.owner = nginx listen.group = nginx pm = dynamic pm.max_children = 50 pm.start_servers = 5 pm.min_spare_servers = 5 pm.max_spare_servers = 35 ``` 在这个示例配置中,我们将PHP-FPM的用户和组设置为nginx,并将PHP-FPM的监听套接字设置为/var/run/php-fpm/php-fpm.sock。 4.重启服务 完成配置后,你需要重启nginx和php-fpm服务,以使配置生效。重启命令如下: ``` sudo systemctl restart nginx sudo systemctl restart php-fpm ``` 到这里,就完成了nginx+PHP的简单部署。同时,为了进一步提升性能,你可以使用Nginx+PHP+FastCGI加速模式。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值