Nginx configuration process

Source: Internet
Author: User

I used the token in advance.

First of all, I found it on the above website. There was a previous installation process. What I found today is to decompress the package directly. We recommend that you install the package after "installation". In fact, it is to decompress the package. However, during this process, it will write your npmserver path to each configuration file,

If you are using a compressed version, you need to change the npmserver installation directory to your own

/Config. ini,/config. XML,/mysql5.1/My. ini,/nginx/vhost. conf, PHP/PHP. ini

It is troublesome, right? If you have a full-text search tool, you can search for it directly in the directory. This is the preparation work. Make sure that the error is not in the path. This is a low-level meaningless error.

 

After the path is changed, PHP. ini basically does not need to be changed. Unless you want to install xdebug for netbean, set it like in my previous article.

People who are not familiar with nginx configuration will have a headache. npmserver has the advantage of dividing the configuration file into a server configuration document (nginx. conf) and a virtual host configuration file (vhost. conf), so you can set them separately, which is very convenient.

In terms of VM configuration, this software also provides INI, XML, and client methods for you to fill in. This is good, but I don't have time to test that much, it is written directly in the configuration file. The following are some notes.

1. nginx. conf basically doesn't need to be moved. By default, you can basically run many websites. If you want to do so, first understand how to change it.

2. The following section will be in vhost. conf by default.

server {    listen       80;    server_name  nginx.a;    location / {        root   I:/NPMserv/www;        index  index.html index.htm index.php default.php;    }    error_page   500 502 503 504  /50x.html;    location = /50x.html {        root   html;    }    location ~ .*\.php?$ {        root           D:/NPMserv/www;        fastcgi_pass   127.0.0.1:9000;        fastcgi_index  index.php;        fastcgi_param  SCRIPT_FILENAME  I:/NPMserv/www$fastcgi_script_name;        include        fastcgi_params;    }}

In the previous article, we configured a virtual path for Apache. Now we configure this virtual path to nginx:

server {    listen       80;    server_name  www.dxpie.com event.dxpie.com;    location / {        root   "I:/EasyPHP/www/pie";        index  index.html index.htm index.php default.php;if ($host ~ ^www\.dxpie\.com.*$) {rewrite ^/?do-(.*)\.html?$ /index.php?act=public&todo=$1 last;}if ($host ~ ^event\.dxpie\.com.*$) {rewrite ^/?([a-zA-Z_]+)(-(\d*))?-p(\d*)\.html?$ /event.php?mod=event&act=$1&id=$3&page=$4&todo=pager last;rewrite ^/?([a-zA-Z_]+)(-(\d*))?-ap(\d*)\.html?$ /event.php?mod=event&act=$1&id=$3&page=$4&todo=ajaxpager last;rewrite ^/?([a-zA-Z_]+)(-(\d*))?\.html?$ /event.php?mod=event&act=$1&id=$3 last;rewrite ^/?(\w+)-(\d+)-c(\d)(\d+)\.html?$ event.php?mod=event&act=$1&pid=$2&gid=$4&index=$3&level=2 last;rewrite ^/?(\w+)-(\d+)-c(\d)(\d+)-ap(\d+)\.html?$ event.php?mod=event&act=$1&pid=$2&gid=$4&index=$3&level=2&page=$5&todo=ajaxpager last;break;}    }    error_page   500 502 503 504  /50x.html;    location = /50x.html {        root   html;    }    location ~ .*\.php?$ {        root           "I:/EasyPHP/www/pie";        fastcgi_pass   127.0.0.1:9000;        fastcgi_index  index.php;        fastcgi_param  SCRIPT_FILENAME  "I:/EasyPHP/www/pie/$fastcgi_script_name";        include        fastcgi_params;    }}

I used this as an example to solve many problems.

2.1. Each host is a server {}

2.2, SERVER_NAME, can be configured with multiple domain names at the same time, not like Apache, a domain name needs to write a node

2.3 set SERVER_NAME under the host, configure the root directory, configure the fastcig parameter for this path, and read the code by yourself

2.4. The above URL rewriting demonstrates the nginx rules. If there is no time to learn the rules in the corresponding. htaccess column, let's take a look at the differences between the two sections:

RewriteCond %{HTTP_HOST} ^www\.dxpie\.com$RewriteRule ^do-(.*)\.html?$ index.php?act=public&todo=$1 [L]RewriteRule ^getfocus\.html?$ index.php?todo=focus [L]RewriteCond %{HTTP_HOST} ^event\.dxpie\.com$RewriteCond %{REQUEST_FILENAME} !-fRewriteCond %{REQUEST_FILENAME} !-dRewriteCond %{HTTP_HOST} ^event\.dxpie\.com$RewriteRule ^([a-zA-Z_]+)(-(\d*))?\.html?$ event.php?mod=event&act=$1&id=$3 [QSA,L]RewriteCond %{HTTP_HOST} ^event\.dxpie\.com$RewriteRule ^([a-zA-Z_]+)(-(\d+))?-p(\d+)\.html?$ event.php?mod=event&act=$1&id=$3&page=$4&todo=pager [QSA,L]RewriteCond %{HTTP_HOST} ^event\.dxpie\.com$RewriteRule ^([a-zA-Z_]+)(-(\d*))?-ap(\d*)\.html?$ event.php?mod=event&act=$1&id=$3&page=$4&todo=ajaxpager [QSA,L]

In comparison, nginx's If statement is easier for most people to accept.

 

2.5. The PHP configuration in the last section, after many tests, it is not enough to include the default fastcgi_params. Therefore, this line is added:

Fastcgi_param script_filename "directory location/$ fastcgi_script_name"; just copy it. I have tested many times and can leave a message if I want to explain it :)

 

3. After the above example, the configuration of other paths is very good. If there is no URL rewrite, it will be much simpler. Basically, you just need to add fastcgi_param, for example, I want to virtualize phpMyAdmin installed with easyphp (My apache, PHP, and MySQL use easyphp, which is quite powerful and convenient. We recommend using it on win, google ).

 

server {    listen       80;    server_name  my.sql;    location / {        root   "I:/EasyPHP/phpmyadmin";        index  index.html index.htm index.php default.php;    }    error_page   500 502 503 504  /50x.html;    location = /50x.html {        root   html;    }    location ~ .*\.php?$ {        root           "I:/EasyPHP/phpmyadmin";        fastcgi_pass   127.0.0.1:9000;        fastcgi_index  index.php;        fastcgi_param  SCRIPT_FILENAME  "I:/EasyPHP/phpmyadmin/$fastcgi_script_name";        include        fastcgi_params;    }}

 

Note that my. SQL points to 127.0.0.1 In the hosts file, so that I can directly use this domain name to manage the database.

 

4. The current accessed database seems to be nginx. Since I already have an environment, I must use it before, so it's my turn to/mysql5.1/My. INI is on the stage. Change datadir to the path of your database. Do not change basedir:

 

[Mysqld] basedir = I:/npmserv/mysql5.1; datadir = I:/npmserv/mysql5.1/data this is the original datadir = "I: /easyphp/MySQL/Data "Port = 3306interactive_timeout = 240wait_timeout = 240

 

Start npmserver now and try accessing localhost. Is there a classic nginx interface? Then try several virtual host directories, phpMyAdmin. Are they all successful? If not, take a closer look.

 

5. By the way, let's share my python configuration on nginx.

#pythonserver {    listen       80;    server_name  py.thon;    location / {            # host and port to fastcgi server            fastcgi_pass 127.0.0.1:9000;            fastcgi_param PATH_INFO $fastcgi_script_name;            fastcgi_param REQUEST_METHOD $request_method;            fastcgi_param QUERY_STRING $query_string;            fastcgi_param CONTENT_TYPE $content_type;            fastcgi_param CONTENT_LENGTH $content_length;            fastcgi_pass_header Authorization;            fastcgi_param REMOTE_ADDR           $remote_addr;            fastcgi_param SERVER_PROTOCOL       $server_protocol;            fastcgi_param SERVER_PORT           $server_port;            fastcgi_param SERVER_NAME           $server_name;            fastcgi_intercept_errors off;    }    error_page   500 502 503 504  /50x.html;    location = /50x.html {        root   html;    }        location ^~ /media/ {alias "I:/python26/Lib/site-packages/django/contrib/admin/media/";    }    location ^~ /site_media/{alias "E:/codes/python/newtest/media/";    }    location ~* ^.+\.(jpg|jpeg|gif|png|ico|css|zip|tgz|gz|rar|bz2|doc|xls|exe|pdf|ppt|txt|tar|mid|midi|wav|bmp|rtf|js|mov)$ {        root           "E:/codes/python/newtest";        access_log off;    }}

 

You will find that there is still a big difference, of course, pytoon plus nginx and Python plus apache I will write another article.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.